Kartou

Correctly Destroying Game (Getting Error)

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?

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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.

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.