-
Notifications
You must be signed in to change notification settings - Fork 488
Description
This Issue is about
- A bug in the API:
- Phaser version(s): 2.19.2
- Live example: https://codepen.io/timiyay/pen/mdLBObB
- What steps produce the bug:
let game = new Phaser.Game()
game.destroy()- What should happen: the game should destroy successfully
- What happens instead: the code crashes
- If there's an error:
Crash occurs at https://github.com/photonstorm/phaser-ce/blob/1af938320a72ebc0cfbd9cc9101fcf1bf17d9808/src/core/Game.js#L1242
Background
We're using a NextJS/React client to run some Phaser games. We're using React's effects inside functional components, since the rendering of a Phaser game is considered a side effect outside of React's control. In development, React has a Strict Mode that will cause these effects to double-render these functional components, in order to help devs identify unintentional side effects in their code
This means our Phaser games are being created, very quickly destroyed, then created again. This is exposing a couple of spots where Phaser currently assumes enough time has passed since new Phaser.Game was called that it's appropriately setup to call destroy.
Do folks see a way we could make the destroy function more resilient to this behaviour, so it doesn't attempt to destroy things that are already dead?
We have some code that wraps our Phaser games, and we've been setting an isDestroying boolean to help in these kind of situations.
I am happy to contribute a PR, once folks have a chance to triage and comment on the issue.
