Goshawk Posted July 27, 2018 Share Posted July 27, 2018 My game is crashing infrequently. I have three scenes, `BootGame`, `PlayGame` and `Menu`. I switch scenes as follows: play_game(){ this.scene.start('PlayGame'); } The game goes back and forth between `PlayGame` and `Menu` but every now and again (about 1 in 50 times), the game crashes when switching scenes. The error in the console is: Uncaught TypeError: Cannot read property 'update' of null at ArcadePhysics.shutdown (project.bundle.js:148885) at EventEmitter.emit (project.bundle.js:2506) at Systems.shutdown (project.bundle.js:35059) at SceneManager.stop (project.bundle.js:68428) at SceneManager.processQueue (project.bundle.js:67563) at SceneManager.update (project.bundle.js:67822) at Game.step (project.bundle.js:119399) at TimeStep.step (project.bundle.js:122906) at step (project.bundle.js:57645) This happens so infrequently, I have no idea what's causing it at the moment other than it has something to do with changing scenes. Is there anything that I'm obviously doing wrong? Am I changing scenes correctly? Are some extra steps I need to take when changing scenes? Link to comment Share on other sites More sharing options...
Goshawk Posted July 28, 2018 Author Share Posted July 28, 2018 Not sure if it's connected but memory usage increases when switching scenes. Which leads me to suspect that I'm not switching scenes correctly as I'm creating new objects (sprites, audio, etc...) each time I start the game scene. I either need to make sure these are all destroyed when starting the menu scene or look at the examples to see where I'm going wrong. Any suggestions? Link to comment Share on other sites More sharing options...
samme Posted July 28, 2018 Share Posted July 28, 2018 Make sure you're using the latest Phase release. The TypeError would be unrelated to memory use. Memory problems cause slowdowns and eventually crash the browser tab. Goshawk 1 Link to comment Share on other sites More sharing options...
Goshawk Posted July 28, 2018 Author Share Posted July 28, 2018 I'm using the latest release. The reason I'm concerned about the memory usage is that both the cumulative increase in memory usage and the crashes occur when switching scenes. This leads me to believe I'm doing something wrong/not doing something I'm supposed to do. I'll blame the wine for leading me to misinterpret the memory usage timeline. Interestingly, I'm now using CANVAS instead of AUTO and the game has yet to crash. Link to comment Share on other sites More sharing options...
Goshawk Posted July 29, 2018 Author Share Posted July 29, 2018 Still unsure what's happening. The topmost error message points to this line: /** * The Scene that owns this plugin is shutting down. * We need to kill and reset all internal properties as well as stop listening to Scene events. * * @method Phaser.Physics.Arcade.ArcadePhysics#shutdown * @since 3.0.0 */ shutdown: function () { var eventEmitter = this.systems.events; eventEmitter.off('update', this.world.update, this.world); // <- this line Link to comment Share on other sites More sharing options...
Goshawk Posted July 29, 2018 Author Share Posted July 29, 2018 I'm now setting a flag to true when I want to switch to the menu scene. The actual `this.scene.start('Menu')` call is now done at the end of `update()`. This seems to have fixed it. I'm sure I'll have a better understanding of what's going on when I become more familiar with the framework. Link to comment Share on other sites More sharing options...
Hauubb Posted July 30, 2018 Share Posted July 30, 2018 Im experiencing this issue as well! What did you do to fix it? Thanks Link to comment Share on other sites More sharing options...
Goshawk Posted July 30, 2018 Author Share Posted July 30, 2018 As above. I set a flag when I want to end the game and I switch the scenes in `update()` update(){ ... if(this.gameEnded){ this.scene.start('Menu'); } } The presumption I've made is that putting it at the end of `update()` ensures that Phaser has done all the updating it needs to do before the scene is destroyed. I have a handful of timeouts and time events in the scene and I wonder if they were causing the problems -- essentially a race condition where the scene was destroyed before updates could be called on it. I haven't done any testing apart from playing the game but it hasn't crashed yet. Have you any timeouts or time events in your scene? Link to comment Share on other sites More sharing options...
Recommended Posts