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

Layer destroy throwing error on scene end #6724

Closed Petah closed 9 months ago

Petah commented 10 months ago

Version

Description

When using layers and a scene ends it throws an error Uncaught TypeError: Cannot read properties of undefined (reading 'destroy')

Example Test Code

Based on this example, just adding a stop after 1 second causes the error: https://labs.phaser.io/edit.html?src=src/game%20objects/layer/add%20sprite%20to%20layer.js&v=3.70.0

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.image('spaceman', 'assets/sprites/exocet_spaceman.png');
    }

    create ()
    {
        const spaceman = this.add.sprite(150, 300, 'spaceman');
        const layer = this.add.layer();
        layer.add([ spaceman ]);
        setTimeout(() => {
            this.scene.stop()
        }, 1000)
    }
}

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: Example
};

const game = new Phaser.Game(config);

Additional Information

image
photonstorm commented 10 months ago

Thank you for spending time reporting this issue. We've already fixed this in the master branch of Phaser and it will be part of the next official release. You can track what's already been fixed by searching closed issues, or by looking at the Change Log.

Petah commented 9 months ago

@photonstorm I tested it out by using "phaser": "git+https://github.com/phaserjs/phaser.git#master" in my project, but still get the error. I also don't see it mentioned here: https://github.com/phaserjs/phaser/blob/master/changelog/3.80/CHANGELOG-v3.80.md

Is there a way to test with the https://labs.phaser.io/ website using the master branch?

Petah commented 9 months ago

Oh it looks like there is some open PRs about it, but not yet merged.

photonstorm commented 9 months ago

Closing as a duplicate of #6675 - looking into it now. Please track on that issue.