diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index dad38fb..23f9e37 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -418,6 +418,8 @@ { super.destroy(options); + this._texture.off('update', this._onTextureUpdate, this); + this._anchor = null; const destroyTexture = typeof options === 'boolean' ? options : options && options.texture; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index dad38fb..23f9e37 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -418,6 +418,8 @@ { super.destroy(options); + this._texture.off('update', this._onTextureUpdate, this); + this._anchor = null; const destroyTexture = typeof options === 'boolean' ? options : options && options.texture; diff --git a/test/core/Sprite.js b/test/core/Sprite.js index c9bc4cb..a3d94a0 100755 --- a/test/core/Sprite.js +++ b/test/core/Sprite.js @@ -1,5 +1,7 @@ 'use strict'; +const path = require('path'); + describe('PIXI.Sprite', function () { describe('width', function () @@ -122,4 +124,22 @@ expect(sprite.containsPoint(point)).to.be.false; }); }); + + describe('destroy', function () + { + it('should destroy while BaseTexture is loading', function () + { + const texture = PIXI.Texture.from(path.resolve(__dirname, 'resources', 'building1.png')); + const sprite = new PIXI.Sprite(texture); + + expect(texture._eventsCount).to.equal(1); + + sprite.destroy(); + + expect(texture._eventsCount).to.equal(0); + + texture.emit('update', texture); + texture.destroy(true); + }); + }); });