fix(image-pipeline): close cleared in-flight source bitmaps

This commit is contained in:
Matthias
2026-04-04 11:40:32 +02:00
parent c0534e04e0
commit 4fa517066f
2 changed files with 53 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ export const SOURCE_BITMAP_CACHE_MAX_ENTRIES = 32;
type CacheEntry = {
promise: Promise<ImageBitmap>;
bitmap?: ImageBitmap;
released?: boolean;
};
const imageBitmapCache = new Map<string, CacheEntry>();
@@ -29,6 +30,7 @@ function deleteCacheEntry(sourceUrl: string): void {
return;
}
entry.released = true;
imageBitmapCache.delete(sourceUrl);
closeBitmap(entry.bitmap);
}
@@ -77,6 +79,12 @@ function getOrCreateSourceBitmapPromise(sourceUrl: string): Promise<ImageBitmap>
const blob = await response.blob();
const bitmap = await createImageBitmap(blob);
if (entry.released || imageBitmapCache.get(sourceUrl) !== entry) {
closeBitmap(bitmap);
return bitmap;
}
entry.bitmap = bitmap;
evictIfNeeded(sourceUrl);
return bitmap;