Jump to content

Error on game.destroy()


Rissk13
 Share

Recommended Posts

I've seen a couple posts pertaining to this issue but the solution didn't work for me. I'm using Meteor for easy user creation and I'm basically watching when a user is signed in/out. When they're signed in, it renders the game, when they log out, it unmounts the react component so in componentWillUnmount I'm trying to call game.destroy() but getting an error:

Uncaught TypeError: Cannot read property 'update' of null
    at MatterPhysics.shutdown (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:188052)
    at MatterPhysics.destroy (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:188073)
    at EventEmitter.emit (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:189980)
    at Systems.destroy (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:136828)
    at SceneManager.destroy (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:135747)
    at Game.runDestroy (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:114668)
    at Game.step (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:114446)
    at TimeStep.step (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:116100)
    at step (modules.js?hash=2b32e82a671a022dced4a8a5e76ab9672c4e24b7:112618)

Based on the other threads I'm guessing this is happening in a scene update. The fix was to call destroy on a keypress instead, which I also tried, but got the same error.

Link to comment
Share on other sites

I checked it in my game on Phaser 3.11 . No component unmounting, just calling game and scene object from console. If i just call game.destroy(); I'm left with the last game frame frozen on my screen with and I only get mouse errors such as this:

Uncaught TypeError: Cannot read property 'queueMouseMove' of null
    at MouseManager.onMouseMove

If I call scene.stop(); on the main and only scene instance the screen goes black, no errors but after calling game.destroy(); after it I get these:

Uncaught TypeError: Cannot read property 'update' of null
    at ArcadePhysics.shutdown (..\node_modules\phaser\src\gameobjects\components\Animation.js:62)
    at ArcadePhysics.destroy (..\node_modules\phaser\src\gameobjects\components\Animation.js:82)
    at EventEmitter.emit (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at Systems.destroy (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at SceneManager.destroy (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at Game.runDestroy (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at Game.step (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at TimeStep.step (..\node_modules\react-dom\cjs\react-dom.development.js:17430)
    at step (..\node_modules\react-dom\cjs\react-dom.development.js:17430)

Uncaught TypeError: Cannot read property 'queueMouseMove' of null
    at MouseManager.onMouseMove (..\node_modules\react-dom\cjs\react-dom.development.js:17430)

If I call game.input.mouse.enabled = false; first and then game.destroy(); there are no errors at all. It's just that the last frozen game frame stays there instead of canvas going black. Maybe that's how it's supposed to work, I don't know. After that I can also manually remove the canvas from the DOM and still no errors. Haven't checked if the game would work after mounting the component again though.

 

I don't think game,destroy(); is working properly right now. Maybe we're just doing something wrong but manually disabling mouse input to get rid of errors doesn't look right. Could you link me the other threads?

 

PS File sources are a little weird because it's a Parcel+nwjs combo.

Link to comment
Share on other sites

Here are a few threads mentioning work arounds and saying game.destroy() should be working as of January.

https://github.com/photonstorm/phaser/issues/3092

https://groups.google.com/forum/#!topic/phaser3-dev/1lUmy42HpAg

 

I haven't tried this yet:

game.destroy = function() {
  this.renderer.destroy();
  this.loop.stop();
  this.canvas.remove();
}

I get the same errors as you though, even with triggering game.destroy() from a gameobject click event instead of the unmounting. For now I ended up just logging the user out and refreshing the page completely.

 

Here are the examples which seem to work fine and don't get the update/mouse errors. But they don't use any physics objects which is what the errors seem to be coming from.

http://labs.phaser.io/edit.html?src=src/public\src\game config\game destroy.js

http://labs.phaser.io/edit.html?src=src\game config\game destroy with multi scenes.js

Link to comment
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...
 Share

  • Recently Browsing   0 members

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