diff --git a/src/core/render/preset/block.ts b/src/core/render/preset/block.ts index 8da2a94..a014470 100644 --- a/src/core/render/preset/block.ts +++ b/src/core/render/preset/block.ts @@ -130,10 +130,8 @@ export class BlockCacher< if (deep & (1 << i)) { const nowIndex = index * this.cacheDepth + i; const item = this.cache.get(nowIndex); - if (item) { - item.destroy(); - this.cache.delete(nowIndex); - } + item?.destroy(); + this.cache.delete(nowIndex); } } } @@ -141,12 +139,10 @@ export class BlockCacher< /** * 清空指定索引的缓存,与 {@link clearCache} 不同的是,这里会直接清空对应索引的缓存,而不是指定分块的缓存(分块->void) */ - clearCacheByIndex(index: number, func: (item: T) => void) { + clearCacheByIndex(index: number) { const item = this.cache.get(index); - if (item) { - item.destroy(); - this.cache.delete(index); - } + item?.destroy(); + this.cache.delete(index); } /** diff --git a/src/core/render/preset/damage.ts b/src/core/render/preset/damage.ts index 216a7cd..74906bb 100644 --- a/src/core/render/preset/damage.ts +++ b/src/core/render/preset/damage.ts @@ -503,7 +503,8 @@ export class Damage extends RenderItem { this.emit('dirtyUpdate', v); // 否则依次渲染并写入缓存 - const temp = cache?.canvas ?? new MotaOffscreenCanvas2D(); + const temp = + block.cache.get(v)?.canvas ?? new MotaOffscreenCanvas2D(); temp.clear(); temp.setHD(true); temp.setAntiAliasing(true);