From 17071b578c41bb383809f1d12c42476b6c74dcee Mon Sep 17 00:00:00 2001 From: photonstorm Date: Thu, 18 Feb 2016 12:59:40 +0000 Subject: [PATCH] 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) --- README.md | 1 + src/gameobjects/BitmapData.js | 8 +++++++- src/pixi/textures/BaseTexture.js | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d925134d..fd3a2cd73 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/ ### Bug Fixes * Groups now check for `child.parent` before calling `removeFromHash` (thanks @spayton #2323 #2338) +* 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) ### Pixi Updates diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js index ae21b3d91..35c73e508 100644 --- a/src/gameobjects/BitmapData.js +++ b/src/gameobjects/BitmapData.js @@ -6,9 +6,13 @@ /** * A BitmapData object contains a Canvas element to which you can draw anything you like via normal Canvas context operations. -* A single BitmapData can be used as the texture for one or many Images/Sprites. +* A single BitmapData can be used as the texture for one or many Images / Sprites. * So if you need to dynamically create a Sprite texture then they are a good choice. * +* Important note: Every BitmapData creates its own Canvas element. Because BitmapData's are now Game Objects themselves, and don't +* live on the display list, they are NOT automatically cleared when you change State. Therefore you _must_ call BitmapData.destroy +* in your State's shutdown method if you wish to free-up the resources the BitmapData used, it will not happen for you. +* * @class Phaser.BitmapData * @constructor * @param {Phaser.Game} game - A reference to the currently running game. @@ -1853,6 +1857,8 @@ Phaser.BitmapData.prototype = { */ destroy: function () { + this.texture.destroy(true); + PIXI.CanvasPool.remove(this); }, diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index e15b29450..f26cf84ab 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -184,7 +184,10 @@ PIXI.BaseTexture.prototype.destroy = function() { PIXI.CanvasPool.removeByCanvas(this.source); - delete PIXI.BaseTextureCache[this.source]; + if (this.source._pixiId) + { + delete PIXI.BaseTextureCache[this.source._pixiId]; + } } this.source = null;