diff --git a/src/core/Application.js b/src/core/Application.js index c48104a..ac72c84 100644 --- a/src/core/Application.js +++ b/src/core/Application.js @@ -179,11 +179,13 @@ */ destroy(removeView) { - const oldTicker = this._ticker; + if (this._ticker) + { + const oldTicker = this._ticker; - this.ticker = null; - - oldTicker.destroy(); + this.ticker = null; + oldTicker.destroy(); + } this.stage.destroy(); this.stage = null; diff --git a/src/core/Application.js b/src/core/Application.js index c48104a..ac72c84 100644 --- a/src/core/Application.js +++ b/src/core/Application.js @@ -179,11 +179,13 @@ */ destroy(removeView) { - const oldTicker = this._ticker; + if (this._ticker) + { + const oldTicker = this._ticker; - this.ticker = null; - - oldTicker.destroy(); + this.ticker = null; + oldTicker.destroy(); + } this.stage.destroy(); this.stage = null; diff --git a/test/core/Application.js b/test/core/Application.js index 2bcec82..902fe88 100644 --- a/test/core/Application.js +++ b/test/core/Application.js @@ -66,4 +66,66 @@ app.destroy(true); }); + + describe('set ticker', function () + { + before(function () + { + this.app = new PIXI.Application(); + /* remove default listener to prevent uncaught exception */ + this.app._ticker.remove(this.app.render, this.app); + }); + + after(function () + { + this.app.destroy(true); + }); + + it('should assign ticker object', function () + { + const ticker = { add: sinon.spy() }; + const _ticker = { remove: sinon.spy() }; + + this.app._ticker = _ticker; + this.app.ticker = ticker; + + expect(_ticker.remove).to.be.calledOnce; + expect(_ticker.remove.args[0][0]).to.be.equal(this.app.render); + expect(_ticker.remove.args[0][1]).to.be.equal(this.app); + + expect(this.app._ticker).to.be.equal(ticker); + expect(ticker.add).to.be.calledOnce; + expect(ticker.add.args[0][0]).to.be.equal(this.app.render); + expect(ticker.add.args[0][1]).to.be.equal(this.app); + expect(ticker.add.args[0][2]).to.be.equal(PIXI.UPDATE_PRIORITY.LOW); + }); + + it('should assign ticker if no ticker', function () + { + const ticker = { add: sinon.spy() }; + + this.app._ticker = null; + this.app.ticker = ticker; + + expect(this.app._ticker).to.be.equal(ticker); + expect(ticker.add).to.be.calledOnce; + expect(ticker.add.args[0][0]).to.be.equal(this.app.render); + expect(ticker.add.args[0][1]).to.be.equal(this.app); + expect(ticker.add.args[0][2]).to.be.equal(PIXI.UPDATE_PRIORITY.LOW); + }); + + it('should assign null ticker', function () + { + const _ticker = { remove: sinon.spy() }; + + this.app._ticker = _ticker; + this.app.ticker = null; + + expect(_ticker.remove).to.be.calledOnce; + expect(_ticker.remove.args[0][0]).to.be.equal(this.app.render); + expect(_ticker.remove.args[0][1]).to.be.equal(this.app); + + expect(this.app._ticker).to.be.null; + }); + }); });