Help with error after `launch`ing a scene that has been `stop`ped

Hey everyone!

I’ve got a confusing problem when I restart a Scene that has previously been stopped. There’s an actual error that gets logged in the console, but the game itself doesn’t stop working per se, except for everything in the game is sped up when it shouldn’t be.

Here’s a link to a game where the issue can be reproduced - https://snowbillr.github.io/archering/. To reproduce it, lose all 3 of your lives (click to fire the arrow and miss the target 3 times), then click the “Play Again” button on the results screen.

You’ll see in the console this error that gets logged:

Then, shoot another arrow. You’ll see that everything has been sped up (physics and tweens in this case).

It looks like the error happens purely because of the Text object that is rendered in the UiScene. If you were to comment out the line in GameScene that launches the UiScene, then no error gets logged and there is no weird speed up.

If you want to try messing with it on your end, clone the github project, run yarn install, and then run yarn dev to start a server up at localhost:8080.

I found what appears to be a related issue here (http://www.html5gamedevs.com/topic/37781-animations-get-faster-switching-scenes/) but there wasn’t any real resolution to it other than doing something hacky.

Thanks for taking a look!

EDIT:

I should mention that I see the error in the latest version of Chrome on MacOS using Phaser v3.15.1-FB. I see it in both Canvas rendering mode and WebGL rendering mode.

I didn’t get the error but I did experience the speed up which is strange. It looks like it is probably a bug which you may want to submit to the github issues.

Maybe instead of:

this.scene.stop('game');
this.scene.stop('ui');
this.scene.start('results');

you could do:

this.scene.stop('ui');
this.scene.switch('results');

And then having an onWake function in the game scene that resets game data and relaunches the UI?

Not sure if that would make a difference but it might be worth a try.

Thanks for taking a look at it. I managed to figure out the issue.

I put some console logging in and noticed that the error I was seeing got printed out prior to the create function being called in the UiScene. So I thought it had something to do with a registry event listener, and that ended up being right.

Turns out, I was assuming that my scene’s destroy method would be called when I called stop on the scene plugin. But that’s not the case. Which meant the code turning off the listeners for the registry events in the UiScene was not getting called, and they were trying to update Text objects that no longer existed. I’m not sure why this manifested in a weird speed up in the game, but it did. When I made sure that those listeners were turned off, then everything was fixed.

What I learned is that the scene doesn’t get destroyed on a stop call, but it does get shutdown. So I added an event handler for the shutdown event in my ui scene and made sure to clean up those registry listeners that updated the text objects, and that fixed it!

Thanks for the extra eyes @B3L7, much appreciated.

2 Likes