rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 261 forks source link

The virtual joystick plugin fails when switching from one scene to another. #180

Closed micheg closed 3 years ago

micheg commented 3 years ago

The virtual joystick plugin fails when switching from one scene to another. Ex: "CursorKeys.js:18 Uncaught TypeError: Cannot read property 'down' of undefined at TouchCursor.shutdown (CursorKeys.js:18)"

This happens because the object inside the for loop is deleted, the file is: phaser3-rex-plugins/plugins/utils/input/CursorKeys.js: and this is the "with the error" method:

shutdown(fromScene) {
    for (var key in this.cursorKeys) {
        this.cursorKeys[key].destroy();
        delete this.cursorKeys;
    }
}

row 16-21 delete should stay outside the for loop, destroying the cursorKeys object after the individual objects have been destroyed with the destroy method. to me it should be:

shutdown(fromScene) {
    for (var key in this.cursorKeys) {
        this.cursorKeys[key].destroy();
    }
    delete this.cursorKeys;
}

I think this is urgent enough, greetings.

rexrainbow commented 3 years ago

Thank for this bug reporting and PR.

Minify file and npm package has been updated.