mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix some memory leaks in 2D object renderers (#5843)
This commit is contained in:
@@ -126,6 +126,10 @@ namespace gdjs {
|
||||
getHeight(): float {
|
||||
return this._pixiObject.height;
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this._pixiObject.destroy(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const BBTextRuntimeObjectRenderer = BBTextRuntimeObjectPixiRenderer;
|
||||
|
@@ -132,6 +132,7 @@ namespace gdjs {
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -393,6 +393,18 @@ namespace gdjs {
|
||||
getTextureHeight() {
|
||||
return this._textureHeight;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// Destroy textures because they are instantiated by this class.
|
||||
for (const borderSprite of this._borderSprites) {
|
||||
borderSprite.destroy({ texture: true });
|
||||
}
|
||||
this._centerSprite.destroy({ texture: true });
|
||||
// Destroy the containers without handling children because they are
|
||||
// already handled above.
|
||||
this._wrapperContainer.destroy(false);
|
||||
this._spritesContainer.destroy(false);
|
||||
}
|
||||
}
|
||||
|
||||
export const PanelSpriteRuntimeObjectRenderer = PanelSpriteRuntimeObjectPixiRenderer;
|
||||
|
@@ -116,11 +116,7 @@ namespace gdjs {
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
// @ts-ignore
|
||||
if (this._renderer.onDestroy) {
|
||||
// @ts-ignore
|
||||
this._renderer.onDestroy();
|
||||
}
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
update(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
|
@@ -564,6 +564,10 @@ namespace gdjs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this._graphics.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
export const ShapePainterRuntimeObjectRenderer = ShapePainterRuntimeObjectPixiRenderer;
|
||||
|
@@ -174,6 +174,11 @@ namespace gdjs {
|
||||
super.stepBehaviorsPreEvents(instanceContainer);
|
||||
}
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the graphics.
|
||||
*/
|
||||
|
@@ -203,6 +203,10 @@ namespace gdjs {
|
||||
setScaleY(newScale: float): void {
|
||||
this._text.scale.y = newScale;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._text.destroy(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Register the class to let the engine use it.
|
||||
|
@@ -145,6 +145,11 @@ namespace gdjs {
|
||||
this._renderer.ensureUpToDate();
|
||||
}
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the extra parameters that could be set for an instance.
|
||||
*/
|
||||
|
@@ -122,6 +122,11 @@ namespace gdjs {
|
||||
getScaleY(): float {
|
||||
return this._pixiObject.scale.y;
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// Keep textures because they are shared by all tile maps.
|
||||
this._pixiObject.destroy(false);
|
||||
}
|
||||
}
|
||||
export const TileMapRuntimeObjectRenderer =
|
||||
gdjs.TileMapRuntimeObjectPixiRenderer;
|
||||
|
@@ -158,6 +158,11 @@ namespace gdjs {
|
||||
);
|
||||
}
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Tilemap file to display.
|
||||
*/
|
||||
|
@@ -124,6 +124,11 @@ namespace gdjs {
|
||||
getTextureHeight() {
|
||||
return this._tiledSprite.texture.height;
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// Keep textures because they are shared by all sprites.
|
||||
this._tiledSprite.destroy(false);
|
||||
}
|
||||
}
|
||||
|
||||
export const TiledSpriteRuntimeObjectRenderer = TiledSpriteRuntimeObjectPixiRenderer;
|
||||
|
@@ -73,9 +73,7 @@ namespace gdjs {
|
||||
|
||||
onDestroyFromScene(instanceContainer: gdjs.RuntimeInstanceContainer): void {
|
||||
super.onDestroyFromScene(instanceContainer);
|
||||
if ((this._renderer as any).onDestroy) {
|
||||
(this._renderer as any).onDestroy();
|
||||
}
|
||||
this._renderer.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -54,6 +54,7 @@ namespace gdjs {
|
||||
*/
|
||||
onDestroy() {
|
||||
this.stop();
|
||||
this._pixiObject.destroy(false);
|
||||
}
|
||||
|
||||
ensureUpToDate() {
|
||||
|
Reference in New Issue
Block a user