Skip to content

Commit 382fed3

Browse files
committed
Added TextureManager.removeKey method and invoke it from Texture.destroy. Fix phaserjs#4461
1 parent 199f598 commit 382fed3

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Notes:
6060
* `Tween.remove` is a new method that immediately removes the Tween from the TweenManager, regardless of what state the tween is in. Once called the tween will no longer exist within any internal TweenManager arrays.
6161
* `SceneManager.isPaused` is a new method that will return if the given Scene is currently paused or not (thanks @samme)
6262
* `ScenePlugin.isPaused` is a new method that will return if the given Scene is currently paused or not (thanks @samme)
63+
* `TextureManager.removeKey` is a new method that will remove a key from the Texture Manager without destroying the texture itself.
6364

6465
### Updates
6566

@@ -73,6 +74,7 @@ Notes:
7374
* The `Clock.now` property value is now synced to be the `TimeStep.time` value when the Clock plugin boots and is no longer `Date.now()` until the first update (thanks @Antriel)
7475
* `Graphics.strokePoints` has renamed the second argument from `autoClose` to `closeShape`. There is also a new third argument `closePath`, which defaults to `true` and automatically closes the path before stroking it. The `endIndex` argument is now the fourth argument, instead of the third.
7576
* `Graphics.fillPoints` has renamed the second argument from `autoClose` to `closeShape`. There is also a new third argument `closePath`, which defaults to `true` and automatically closes the path before filling it. The `endIndex` argument is now the fourth argument, instead of the third.
77+
* Calling `Texture.destroy` will now call `TextureManager.removeKey` to ensure the key is removed from the manager, should you destroy a texture directly, rather than going via `TextureManager.remove`. Fix #4461 (thanks @BigZaphod)
7678

7779
### Bug Fixes
7880

src/textures/Texture.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ var Texture = new Class({
461461
this.source = [];
462462
this.dataSource = [];
463463
this.frames = {};
464+
465+
this.manager.removeKey(this.key);
466+
464467
this.manager = null;
465468
}
466469

src/textures/TextureManager.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ var TextureManager = new Class({
213213
// By this point key should be a Texture, if not, the following fails anyway
214214
if (this.list.hasOwnProperty(key.key))
215215
{
216-
delete this.list[key.key];
217-
218216
key.destroy();
219217

220218
this.emit(Events.REMOVE, key.key);
@@ -223,6 +221,26 @@ var TextureManager = new Class({
223221
return this;
224222
},
225223

224+
/**
225+
* Removes a key from the Texture Manager but does not destroy the Texture that was using the key.
226+
*
227+
* @method Phaser.Textures.TextureManager#removeKey
228+
* @since 3.17.0
229+
*
230+
* @param {string} key - The key to remove from the texture list.
231+
*
232+
* @return {Phaser.Textures.TextureManager} The Texture Manager.
233+
*/
234+
removeKey: function (key)
235+
{
236+
if (this.list.hasOwnProperty(key))
237+
{
238+
delete this.list[key];
239+
}
240+
241+
return this;
242+
},
243+
226244
/**
227245
* Adds a new Texture to the Texture Manager created from the given Base64 encoded data.
228246
*

0 commit comments

Comments
 (0)