Skip to content

Commit 17071b5

Browse files
committed
BaseTexture.destroy wasn't correctly removing the texture from the BaseTextureCache if it was a cached CanvasPool entry (such as Text objects use), causing drawImage errors in Canvas mode, and just blank textures in WebGL (thanks @civet phaserjs#2339)
1 parent 46cc05a commit 17071b5

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
323323
### Bug Fixes
324324

325325
* Groups now check for `child.parent` before calling `removeFromHash` (thanks @spayton #2323 #2338)
326+
* BaseTexture.destroy wasn't correctly removing the texture from the BaseTextureCache if it was a cached CanvasPool entry (such as Text objects use), causing drawImage errors in Canvas mode, and just blank textures in WebGL (thanks @civet #2339)
326327

327328
### Pixi Updates
328329

src/gameobjects/BitmapData.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
/**
88
* A BitmapData object contains a Canvas element to which you can draw anything you like via normal Canvas context operations.
9-
* A single BitmapData can be used as the texture for one or many Images/Sprites.
9+
* A single BitmapData can be used as the texture for one or many Images / Sprites.
1010
* So if you need to dynamically create a Sprite texture then they are a good choice.
1111
*
12+
* Important note: Every BitmapData creates its own Canvas element. Because BitmapData's are now Game Objects themselves, and don't
13+
* live on the display list, they are NOT automatically cleared when you change State. Therefore you _must_ call BitmapData.destroy
14+
* in your State's shutdown method if you wish to free-up the resources the BitmapData used, it will not happen for you.
15+
*
1216
* @class Phaser.BitmapData
1317
* @constructor
1418
* @param {Phaser.Game} game - A reference to the currently running game.
@@ -1853,6 +1857,8 @@ Phaser.BitmapData.prototype = {
18531857
*/
18541858
destroy: function () {
18551859

1860+
this.texture.destroy(true);
1861+
18561862
PIXI.CanvasPool.remove(this);
18571863

18581864
},

src/pixi/textures/BaseTexture.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ PIXI.BaseTexture.prototype.destroy = function()
184184
{
185185
PIXI.CanvasPool.removeByCanvas(this.source);
186186

187-
delete PIXI.BaseTextureCache[this.source];
187+
if (this.source._pixiId)
188+
{
189+
delete PIXI.BaseTextureCache[this.source._pixiId];
190+
}
188191
}
189192

190193
this.source = null;

0 commit comments

Comments
 (0)