Clean up object URLs in genGenTextSprites and getGenExColors

Both functions load images from skin files and use them to extract data
(letter sprites and colors). After extracting the data, the images are
no longer needed. Clean up object URLs at this point to prevent leaks.
This commit is contained in:
Claude 2025-11-29 01:10:03 +00:00
parent 668f1061d9
commit 339705ef55
No known key found for this signature in database
2 changed files with 19 additions and 2 deletions

View file

@ -135,7 +135,16 @@ async function genGenTextSprites(zip) {
sprites.forEach((sprite) => {
letterWidths[sprite.name] = sprite.width;
});
return [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)];
const result = [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)];
// Clean up object URL if the image is an HTMLImageElement with a blob URL
// (ImageBitmap doesn't have a src property, so this only affects the fallback path)
if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) {
URL.revokeObjectURL(img.src);
}
return result;
}
// A promise that, given an array buffer returns a skin style object

View file

@ -224,7 +224,7 @@ export async function getGenExColors(
// that with getColorAt, but I don't know a great way to make that type
// safe. So, we'll just do this for now, where we explicitly call getColorAt
// for each key.
return {
const colors = {
// (1) x=48: item background (background to edits, listviews, etc.)
itemBackground: getColorAt(48),
// (2) x=50: item foreground (text colour of edits, listviews, etc.)
@ -270,4 +270,12 @@ export async function getGenExColors(
// (22) x=90 List view background colour selected
listTextSelectedBackground: getColorAt(90),
};
// Clean up object URL if the image is an HTMLImageElement with a blob URL
// (ImageBitmap doesn't have a src property, so this only affects the fallback path)
if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) {
URL.revokeObjectURL(img.src);
}
return colors;
}