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
37.16k stars 7.1k forks source link

Phaser.Time.Timeline Errors on calling destroy #6844

Closed saintflow47 closed 3 months ago

saintflow47 commented 4 months ago

Version

Description

An issue happens on both versions when trying to destroy a timeline like this, even while it is playing. The error is different for each phaser version though.

Example Test Code

                const follower = this.scene.add.follower(curve, 0, 0, "img", "id/ranks/star");
                follower.setVisible(false)
                follower.startFollow({
                    from: pathProgress - 0.5 < 0 ? 0 : pathProgress - 0.5,
                    to: pathProgress,
                    duration: singleDuration,
                    delay: fullDuration-i*singleDuration*mp
                });
                const bloom = follower.postFX.addGlow(0xffffff,3,2)
                const timeline = this.scene.add.timeline([
                    {
                        at: fullDuration-i*singleDuration*mp,
                        run: () => follower.setVisible(true)
                    },
                    {
                        at: fullDuration-i*singleDuration*mp,
                        tween: {
                            targets: follower,
                            angle: this.getStarAngle(starCount, i)-(360*2),
                            duration: singleDuration,
                        }
                    },
                    {
                        at: fullDuration-i*singleDuration*mp+600,
                        tween: {
                            targets: bloom,
                            innerStrength: 0,
                            outerStrength: 0,
                            duration: 500,
                        }
                    }
                ]).on("complete", () => {
                    if(this?.visible){
                        follower?.destroy();
                        this?.addDivisionStarInFinalPosition(curve, pathProgress, starCount, i);
                    }
                }).play()
if(timeline?.isPlaying())  timeline.destroy();

on 3.85.0-beta.1 the error is as follows: Uncaught ReferenceError: i is not defined at Timeline2.clear (phaser.js:233673:14) at Timeline2.destroy (phaser.js:233752:14) 2024_06_24_161023

on 3.80.1 the error is as follows: TypeError: Cannot read properties of null (reading 'events') at Timeline2.destroy (phaser.js:233464:41) 2024_06_24_164248

zekeatchan commented 4 months ago

Hi @saintflow47. Could you provide full source code and if possible a link to jsfiddle or codepen so we can investigate further? Thanks.

saintflow47 commented 4 months ago

https://phaser.io/sandbox/DPz6DKZC

here is a minimal case

zekeatchan commented 4 months ago

Hi @saintflow47. It seems there's a missing var in the for loop in the Phaser.Time.Timeline#clear method. We have fixed this and pushed it to the master branch. It will be part of the next release. Do test it out and let us know if you encounter any issues.