Skip to content

Commit ced2d34

Browse files
committed
BitmapMask and GeometryMask both have new destroy methods which clear their references, freeing them for gc.
1 parent d2db5ca commit ced2d34

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* If you're using Webpack with Phaser you'll need to update your config to match our new one.
1313
* We've swapped use of the Webpack DefinePlugin so instead of setting a global flag for the compilation of the Canvas and WebGL renderers, we now use a typeof check instead. This means you should now be able to ingest the Phaser source more easily outside of Webpack without having to define any global vars first (thanks @tgrajewski)
1414
* Under Webpack we still use the raw-loader to import our shader source, but outside of Webpack we now use `require.extensions` to load the shader source via fs. This should allow you to bundle Phaser with packages other than Webpack more easily (thanks @tgrajewski)
15-
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load images files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
15+
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load image files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
16+
* BitmapMask and GeometryMask both have new `destroy` methods which clear their references, freeing them for gc.
1617

1718
### Bug Fixes
1819

src/display/mask/BitmapMask.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ var BitmapMask = new Class({
191191
postRenderCanvas: function ()
192192
{
193193
// NOOP
194+
},
195+
196+
/**
197+
* Destroys this BitmapMask and nulls any references it holds.
198+
*
199+
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
200+
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
201+
*
202+
* @method Phaser.Display.Masks.BitmapMask#destroy
203+
* @since 3.6.1
204+
*/
205+
destroy: function ()
206+
{
207+
this.bitmapMask = null;
208+
this.mainTexture = null;
209+
this.maskTexture = null;
210+
this.mainFramebuffer = null;
211+
this.maskFramebuffer = null;
194212
}
195213

196214
});

src/display/mask/GeometryMask.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ var GeometryMask = new Class({
131131
postRenderCanvas: function (renderer)
132132
{
133133
renderer.currentContext.restore();
134+
},
135+
136+
/**
137+
* Destroys this GeometryMask and nulls any references it holds.
138+
*
139+
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
140+
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
141+
*
142+
* @method Phaser.Display.Masks.GeometryMask#destroy
143+
* @since 3.6.1
144+
*/
145+
destroy: function ()
146+
{
147+
this.geometryMask = null;
134148
}
135149

136150
});

src/gameobjects/components/Mask.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ var Mask = {
5555
* @method Phaser.GameObjects.Components.Mask#clearMask
5656
* @since 3.6.2
5757
*
58+
* @param {boolean} [destroyMask=false] - Destroy the mask before clearing it?
59+
*
5860
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
5961
*/
60-
clearMask: function ()
62+
clearMask: function (destroyMask)
6163
{
64+
if (destroyMask === undefined) { destroyMask = false; }
65+
66+
if (destroyMask)
67+
{
68+
this.mask.destroy();
69+
}
70+
6271
this.mask = null;
6372

6473
return this;

0 commit comments

Comments
 (0)