I have uncovered what seems like a major bug in versions 3.15.0 and 3.15.1, where under certain conditions Scenes will continually restart in an infinite loop when an exception is raised. The detailed setup to reproduce is below, but the gist is as follows:
-
Create two
Scene
classes (e.g.BootScene
andLoadScene
) which both inherit fromPhaser.Scene
-
Start the game on the
BootScene
and then start theLoadScene
from theBootScene
-
Raise an exception somewhere in
LoadScene
. Either inpreload
orcreate
, it doesn’t seem to matter. I did this for example by calling a scene function that doesn’t exist,this.foobar()
In Phaser 3.15.0 and above, this will raise the following stack trace, repeated over and over again in an infinite loop. It seems that the scene is continually trying to restart itself on the exception, and thus continually raises the error:
Uncaught TypeError: this.foobar is not a function
at DemoLoadScene.preload (load.js:10)
at SceneManager.bootScene (SceneManager.js:474)
at SceneManager.start (SceneManager.js:1142)
at SceneManager.processQueue (SceneManager.js:288)
at SceneManager.update (SceneManager.js:547)
at Game.step (Game.js:538)
at TimeStep.step (TimeStep.js:560)
at step (RequestAnimationFrame.js:104)
In Phaser 3.14.0 and below, this exact same code raises the following error only a single time and then execution stops (i.e. much more sane and expected behavior):
Uncaught TypeError: this.foobar is not a function
at DemoLoadScene.preload (load.js:10)
at SceneManager.bootScene (SceneManager.js:474)
at SceneManager.start (SceneManager.js:1142)
at SceneManager.processQueue (SceneManager.js:288)
at SceneManager.update (SceneManager.js:547)
at Game.step (Game.js:553)
at TimeStep.step (TimeStep.js:560)
at step (RequestAnimationFrame.js:102)
It should also be noted that the bad behavior in 3.15.0 does not occur when you raise the error in the BootScene
so it seems to only occur in the context of one Scene starting from inside another. This seems like a pretty major and fundamental issue so I’m surprised that no one has raised it before. At the moment my only option is to revert back to 3.14.0 until this is solved.
To reproduce this error, set up a small Phaser app with index.js
scenes/boot.js
and scenes/load.js
as follows:
// index.js
import Phaser from "phaser"
import DemoBootScene from "./scenes/boot.js"
import DemoLoadScene from "./scenes/load.js"
const CONFIG = {
type: Phaser.AUTO,
width: 800,
height: 600,
}
let demoApp = new Phaser.Game(CONFIG)
demoApp.scene.add("boot", DemoBootScene)
demoApp.scene.add("load", DemoLoadScene)
demoApp.scene.start("boot")
// scenes/boot.js
import Phaser from "phaser"
class DemoBootScene extends Phaser.Scene {
constructor() {
super(...arguments)
}
preload() {}
create() {
this.scene.start("load")
this.scene.stop()
}
update() {}
}
export default DemoBootScene
// scenes/load.js
import Phaser from "phaser"
class DemoLoadScene extends Phaser.Scene {
constructor() {
super(...arguments)
}
preload() {
this.foobar() // deliberately raise an exception
}
create() {}
update() {}
}
export default DemoLoadScene