phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.95k stars 7.08k forks source link

myTweenRef.stop() on 'destroyed' tween throws 'TypeError: this.callbacks is null' #6243

Closed michalfialadev closed 1 year ago

michalfialadev commented 1 year ago

Version

Description

ISSUE When creating a Tween and keeping a reference, then after the tween completes and we call: myTweenRef.stop()

app crashes with following error log: TypeError: this.callbacks is null

NOTES

Example Test Code

NOTE: this.animTween has finished at this point.

console.log(">>>")
console.log(this.animTween.isFinished());       // false
console.log(this.animTween.isActive());         // false
console.log(this.animTween.isDestroyed());      // true
console.log(this.animTween.isPending());        // false
console.log(this.animTween.isPendingRemove());  // false
console.log(this.animTween.isPlaying());        // false
console.log(this.animTween.isRemoved());        // false
console.log(this.animTween.isPaused());         // false
console.log(this.animTween.isSeeking);          // false
console.log(this.animTween.isStartDelayed());   // false
try{
    this.animTween.stop();
}
catch(e:any) {
    console.log(e);
}

////////////////////////////////////// // PHASER code in question that throws //////////////////////////////////////

dispatchEvent: function (event, callback) {
        if (!this.isSeeking) {
            this.emit(event, this, this.targets);
            // following line throws (this.callbacks is null)
            var handler = this.callbacks[callback];
            if (handler) {
                handler.func.apply(this.callbackScope, [ this, this.targets ].concat(handler.params));
            }
        }
    }

Additional Information

photonstorm commented 1 year ago

Thank you for spending time reporting this issue. However, we've already fixed this in the master branch of Phaser, and it will be part of the next beta release.

photonstorm commented 1 year ago

For the record, the stop method now bails if the Tween destroy state has been set. Although really if the Tween is being re-used over and over, it should be set to persist: true in the tween config, but this will at least stop a runtime error.

michalfialadev commented 1 year ago

For the record, the stop method now bails if the Tween destroy state has been set. Although really if the Tween is being re-used over and over, it should be set to persist: true in the tween config, but this will at least stop a runtime error.

persist: true is the proper way to do it, thanks!