Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior of queued scene operations #5359

Closed
telinc1 opened this issue Oct 17, 2020 · 3 comments
Closed

Unexpected behavior of queued scene operations #5359

telinc1 opened this issue Oct 17, 2020 · 3 comments

Comments

@telinc1
Copy link

telinc1 commented Oct 17, 2020

Version

  • Phaser Version: 3.24.1 / 3.50.0-beta.9

Description

If a new scene is pending to be added on a given frame, all other scene operations queued for that frame (such as re-arranging or stopping existing scenes) will be postponed until the next frame.

This behavior seems intentional and is caused by a return statement in SceneManager#processQueue (removing that statement or calling processQueue twice from update fixes the example below). However, it seems very counter-intuitive and I can't find any obvious documentation for it. Additionally, the commit that caused it (123c8f8) doesn't seem directly related. This is why I'm wondering whether it's intended (and if it is, what it fixes) or whether it's an oversight.

Example Test Code

Click the screen to add a new scene (SceneB) and shut down the existing one (SceneA) at the same time. Because SceneB was added, SceneA won't shut down until the next frame. Thus, its update method will run even though this.scene.stop() was called during the previous frame. In this (highly contrived) case, the extra invocation of update causes an error.

class SceneA extends Phaser.Scene {
    constructor(){
        super({key: 'sceneA', active: true});
    }

    create(){
        this.shuttingDown = false;
        this.add.text(10, 10, 'SceneA. Click to stop SceneA and add SceneB.');

        this.input.once('pointerup', () => {
            this.shuttingDown = true;
        });
    }

    update(){
        if(this.shuttingDown){
            window.alert('SceneA shutting down.');

            this.scene.stop();
            this.scene.add('sceneB', SceneB);
        }
    }
}

class SceneB extends Phaser.Scene {
    constructor(){
        super({key: 'sceneB', active: true});
    }

    create(){
        this.add.text(10, 10, 'SceneB.');
    }
}

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#000000',
    parent: 'phaser-example',
    scene: [SceneA]
};

var game = new Phaser.Game(config);
@photonstorm
Copy link
Collaborator

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/error-referencing-this-in-update-when-switching-scenes/8143/2

@photonstorm
Copy link
Collaborator

I can't see a reason to return here, so am going to remove it and allow whatever else is in the queue to run.

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants