BitmapMask and GeometryMask both have new destroy methods which clear their references, freeing them for gc.

This commit is contained in:
Richard Davey 2018-04-23 00:13:04 +01:00
parent d2db5cae89
commit ced2d34b34
4 changed files with 44 additions and 2 deletions

View file

@ -12,7 +12,8 @@
* If you're using Webpack with Phaser you'll need to update your config to match our new one.
* 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)
* 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)
* 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.
* 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.
* BitmapMask and GeometryMask both have new `destroy` methods which clear their references, freeing them for gc.
### Bug Fixes

View file

@ -191,6 +191,24 @@ var BitmapMask = new Class({
postRenderCanvas: function ()
{
// NOOP
},
/**
* Destroys this BitmapMask and nulls any references it holds.
*
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
*
* @method Phaser.Display.Masks.BitmapMask#destroy
* @since 3.6.1
*/
destroy: function ()
{
this.bitmapMask = null;
this.mainTexture = null;
this.maskTexture = null;
this.mainFramebuffer = null;
this.maskFramebuffer = null;
}
});

View file

@ -131,6 +131,20 @@ var GeometryMask = new Class({
postRenderCanvas: function (renderer)
{
renderer.currentContext.restore();
},
/**
* Destroys this GeometryMask and nulls any references it holds.
*
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
*
* @method Phaser.Display.Masks.GeometryMask#destroy
* @since 3.6.1
*/
destroy: function ()
{
this.geometryMask = null;
}
});

View file

@ -55,10 +55,19 @@ var Mask = {
* @method Phaser.GameObjects.Components.Mask#clearMask
* @since 3.6.2
*
* @param {boolean} [destroyMask=false] - Destroy the mask before clearing it?
*
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
*/
clearMask: function ()
clearMask: function (destroyMask)
{
if (destroyMask === undefined) { destroyMask = false; }
if (destroyMask)
{
this.mask.destroy();
}
this.mask = null;
return this;