Skip to content

Commit a272324

Browse files
committed
CanvasTexture.destroy is a new method that specifically handles the destruction of the CanvasTexture and all of its associated typed arrays. This prevents a memory leak when creating and destroying lots of RenderTextures (which are CanvasTexture backed). Fix phaserjs#4239
1 parent 41286b5 commit a272324

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ one set of bindings ever created, which makes things a lot cleaner.
248248
* `Container.getFirst` was using an incorrect Array Utils function `GetFirstElement`, when it should have been using `GetFirst`. It now uses the correct function. Fix #4244 (thanks @miran248)
249249
* `List.getFirst` was using an incorrect Array Utils function `GetFirstElement`, when it should have been using `GetFirst`. It now uses the correct function. Fix #4244 (thanks @miran248)
250250
* Fixed an issue where changing the viewport or size of a Camera belonging to a RenderTexture, it wouldn't impact the rendering and objects will still render outside of the viewport range. It's now converted to a proper gl scissor rect by the renderer, meaning you can limit the area rendered to by adjusting the internal Render Texture cameras viewport. Fix #4243 (thanks @hackhat)
251+
* `CanvasTexture.destroy` is a new method that specifically handles the destruction of the CanvasTexture and all of its associated typed arrays. This prevents a memory leak when creating and destroying lots of RenderTextures (which are CanvasTexture backed). Fix #4239 (thanks @sjb933)
251252

252253
### Examples and TypeScript
253254

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,12 @@ var RenderTexture = new Class({
980980
}
981981

982982
this.texture.destroy();
983+
this.camera.destroy();
984+
985+
this.canvas = null;
986+
this.context = null;
987+
this.framebuffer = null;
988+
this.texture = null;
983989
}
984990
}
985991

src/textures/CanvasTexture.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,25 @@ var CanvasTexture = new Class({
595595
}
596596

597597
return this;
598+
},
599+
600+
/**
601+
* Destroys this Texture and releases references to its sources and frames.
602+
*
603+
* @method Phaser.Textures.CanvasTexture#destroy
604+
* @since 3.16.0
605+
*/
606+
destroy: function ()
607+
{
608+
Texture.prototype.destroy.call(this);
609+
610+
this._source = null;
611+
this.canvas = null;
612+
this.context = null;
613+
this.imageData = null;
614+
this.data = null;
615+
this.pixels = null;
616+
this.buffer = null;
598617
}
599618

600619
});

0 commit comments

Comments
 (0)