📝 Fixed some memory problems

RenderTexture leak in IsometricImageFurniVisualization, every direction change or thumbnail update leaked a GPU RenderTexture.
Image object leak in FurnitureDynamicThumbnailVisualization, now clears callbacks and src after use.
Image object leak in FurnitureBadgeDisplayVisualization, image objects never cleaned up
This commit is contained in:
duckietm
2026-03-31 15:20:28 +02:00
parent 2138d3a820
commit 44cb722f54
3 changed files with 29 additions and 3 deletions
@@ -340,6 +340,15 @@ export class FurnitureBadgeDisplayVisualization extends FurnitureAnimatedVisuali
ctx.clearRect(0, 0, badgeCanvas.width, badgeCanvas.height); ctx.clearRect(0, 0, badgeCanvas.width, badgeCanvas.height);
ctx.drawImage(img, 0, 0, badgeCanvas.width, badgeCanvas.height); ctx.drawImage(img, 0, 0, badgeCanvas.width, badgeCanvas.height);
tex.source.update(); tex.source.update();
img.onload = null;
img.onerror = null;
img.src = '';
};
img.onerror = () =>
{
img.onload = null;
img.onerror = null;
img.src = '';
}; };
img.src = badgeUrl; img.src = badgeUrl;
} }
@@ -33,10 +33,16 @@ export class FurnitureDynamicThumbnailVisualization extends IsometricImageFurniV
} else { } else {
this.setThumbnailImages(null); this.setThumbnailImages(null);
} }
image.onload = null;
image.onerror = null;
image.src = '';
}; };
image.onerror = () => { image.onerror = () => {
this.setThumbnailImages(null); this.setThumbnailImages(null);
image.onload = null;
image.onerror = null;
image.src = '';
}; };
} else { } else {
this.setThumbnailImages(null); this.setThumbnailImages(null);
@@ -61,6 +61,9 @@ export class IsometricImageFurniVisualization extends FurnitureAnimatedVisualiza
if (this._thumbnailImageNormal) { if (this._thumbnailImageNormal) {
this.addThumbnailAsset(this._thumbnailImageNormal, 64); this.addThumbnailAsset(this._thumbnailImageNormal, 64);
} else { } else {
if (this._thumbnailTexture instanceof RenderTexture) {
this._thumbnailTexture.destroy(true);
}
this._thumbnailTexture = null; this._thumbnailTexture = null;
this._thumbnailLayerId = -1; this._thumbnailLayerId = -1;
} }
@@ -82,6 +85,9 @@ export class IsometricImageFurniVisualization extends FurnitureAnimatedVisualiza
const asset = this.getAsset(assetName, layerId); const asset = this.getAsset(assetName, layerId);
if (asset) { if (asset) {
if (this._thumbnailTexture instanceof RenderTexture) {
this._thumbnailTexture.destroy(true);
}
this._thumbnailTexture = this.generateTransformedThumbnail(k, asset); this._thumbnailTexture = this.generateTransformedThumbnail(k, asset);
} }
@@ -106,6 +112,7 @@ export class IsometricImageFurniVisualization extends FurnitureAnimatedVisualiza
protected generateTransformedThumbnail(texture: Texture, asset: IGraphicAsset): Texture { protected generateTransformedThumbnail(texture: Texture, asset: IGraphicAsset): Texture {
const assetWidth = asset.width; const assetWidth = asset.width;
const assetHeight = asset.height; const assetHeight = asset.height;
let outlineTexture: RenderTexture = null;
if(this._hasOutline) if(this._hasOutline)
{ {
@@ -124,10 +131,10 @@ export class IsometricImageFurniVisualization extends FurnitureAnimatedVisualiza
container.addChild(background, imageSprite); container.addChild(background, imageSprite);
const flatRenderTexture = RenderTexture.create({ width: bgWidth, height: bgHeight, resolution: 1 }); outlineTexture = RenderTexture.create({ width: bgWidth, height: bgHeight, resolution: 1 });
GetRenderer().render({ container, target: flatRenderTexture, clear: true }); GetRenderer().render({ container, target: outlineTexture, clear: true });
texture = flatRenderTexture; texture = outlineTexture;
} }
texture.source.scaleMode = 'linear'; texture.source.scaleMode = 'linear';
@@ -197,6 +204,10 @@ export class IsometricImageFurniVisualization extends FurnitureAnimatedVisualiza
const renderTexture = RenderTexture.create({ width: renderWidth, height: renderHeight, resolution: 1 }); const renderTexture = RenderTexture.create({ width: renderWidth, height: renderHeight, resolution: 1 });
GetRenderer().render({ container: transformedSprite, target: renderTexture, clear: true }); GetRenderer().render({ container: transformedSprite, target: renderTexture, clear: true });
if (outlineTexture) {
outlineTexture.destroy(true);
}
return renderTexture; return renderTexture;
} }