Jump to content

Correctly Destroying Game (Getting Error)


Kartou
 Share

Recommended Posts

Hi!

 

I'm having trouble with destroying the game after use. I'm calling game.destroy(), but this does not properly shut down the core game loop, hence crashing in:

c.Game.updatec.RequestAnimationFrame.updateRAFwindow.requestAnimationFrame.forceSetTimeOut._onLoop

with the error:

Uncaught TypeError: Cannot read property 'slowMotion' of null

From the source code it looks like game.destroy() should cancel all further updates etc. Maybe I'm missing something?

 

Link to comment
Share on other sites

I have created an example in the sandbox that displays the error. Please see error in the console after pressing the left arrow:

http://phaser.io/sandbox/edit/mqmaJDwh

It looks like the destroy does not properly stop the requestAnimationFrame. Maybe I'm not supposed to call game.destroy() at that time?

    1. c.Game.updateLogic @ phaser.js:34680
      c.Game.update @ phaser.js:34619
      c.RequestAnimationFrame.updateRAF @ phaser.js:58258
      window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.js:58242
Link to comment
Share on other sites

  • 1 year later...
On 1/13/2016 at 7:22 AM, Kartou said:

It looks like the destroy does not properly stop the requestAnimationFrame. Maybe I'm not supposed to call game.destroy() at that time?

 `destroy` has done its job; the problem is that you're still in the middle of `updateLogic`, which can't continue because `game.stage` and other references are now missing.

Try calling `destroy` from a keypress handler instead.

Link to comment
Share on other sites

Samme! Thanx a lot for this hint.

I realized that the updateLogic was still running. But I had no clue how to stop or break through it. I thought maybe I have to delete a reference to something or I don't know. But I spent 2 days now looking for a solution. Restructuring code. Finding work arounds etc. And in the End it works by just using a simple (button) click event. This should definitely be more obvious or explained somewhere. It's crucial, isn't it?

Thanks again. So glad.

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...