spartanboy56

Multiple errors when using game.destroy(true)

Recommended Posts

Hey yall,

I'm currently trying to make a game with phaser 3 for a school project and I'm getting some errors I don't quite understand when try to I destroy the game on say a log out prompt. I have a UI setup in its own scene and when I fire the method

this.sys.game.destroy(true)

 as seen in this example: https://labs.phaser.io/edit.html?src=src/game config/game destroy.js

Uncaught TypeError: this.data.destroy is not a function
    at ArcadeSprite.destroy (GameObject.js:555)
    at DisplayList.shutdown (DisplayList.js:206)
    at DisplayList.destroy (DisplayList.js:224)
    at EventEmitter.emit (index.js:202)
    at Systems.destroy (Systems.js:727)
    at SceneManager.destroy (SceneManager.js:1561)
    at Game.runDestroy (Game.js:777)
    at Game.step (Game.js:523)
    at TimeStep.step (TimeStep.js:560)
    at step (RequestAnimationFrame.js:104)


Systems.js:727 Uncaught TypeError: Cannot read property 'emit' of null
    at Systems.destroy (Systems.js:727)
    at SceneManager.destroy (SceneManager.js:1561)
    at Game.runDestroy (Game.js:777)
    at Game.step (Game.js:523)
    at TimeStep.step (TimeStep.js:560)
    at step (RequestAnimationFrame.js:104)

The second one is spit out indefinitely, so this tells me that the game loop itself isn't being shut down. After this happens the canvas is still rendered and the game is frozen at the last frame and I'm unable to do anything else.

Has anyone had this issue with destroying the current game? For reference here is my scene class where the action is happening on a button click.

import phaser from 'phaser';

let actionKey;
 
export default class PauseScene extends phaser.Scene {
  constructor () {
    super('Pause');
  }
 
  preload () {
  	
  }
 
  create () {
    

    let uiPanel = this.add.image(400, 300, 'uiPanel')
    uiPanel.setScale(4)
    let xButton = this.add.sprite(uiPanel.x - 170, uiPanel.y - 170, 'brwnX').setTint(0xff0000).setInteractive()
    let logOutButton = this.add.sprite(uiPanel.x - 170, uiPanel.y - 100, 'greyBtn').setInteractive()
    let deleteSaveButton = this.add.sprite(uiPanel.x - 170, uiPanel.y, 'brownBtn').setTint(0xff0000).setInteractive()

    let logOutText = this.add.text(logOutButton.x + 20, logOutButton.y - 10, 'Log Out')
    let deleteSaveText = this.add.text(deleteSaveButton.x + 20, deleteSaveButton.y - 10, 'Delete current save')

    // Set on click event
    xButton.on('pointerdown', function (pointer) {
      this.scene.switch('Game')
      //this.scene.stop()
    }, this)

    logOutButton.on('pointerdown', function (pointer) {
      //this.canvas.remove()
      this.sys.game.destroy(true)
      //window.game = null
    }, this)

  }

  update () {
    
  }
};

 

I really appreciate any help on the matter!

 

 

 

Share this post


Link to post
Share on other sites

The first error is caused by Phaser trying to destroy the Data Manager of an Arcade Sprite. Do you ever touch the `data` property on any of your Arcade Sprites? If yes, consider switching to the `getData` and `setData` methods on the Game Object instead. Phaser expects the `data` property to be a Data Manager, so setting it to anything else without special precautions will result in an error like yours.

I can't immediately pinpoint the cause of the second error. For some reason, the Event Emitter of a Scene's Systems object doesn't exist and I'm pretty sure that shouldn't ever happen (any external references to the Event Emitter would be cleaned up by whichever plugin uses them, so there's no need to destroy it when destroying a Scene). The Systems object is rarely touched, so I doubt you've ended up doing something to it from your code, but I can't think of any other possibility.

Share this post


Link to post
Share on other sites
28 minutes ago, Telinc1 said:

The first error is caused by Phaser trying to destroy the Data Manager of an Arcade Sprite. Do you ever touch the `data` property on any of your Arcade Sprites? If yes, consider switching to the `getData` and `setData` methods on the Game Object instead. Phaser expects the `data` property to be a Data Manager, so setting it to anything else without special precautions will result in an error like yours.

I can't immediately pinpoint the cause of the second error. For some reason, the Event Emitter of a Scene's Systems object doesn't exist and I'm pretty sure that shouldn't ever happen (any external references to the Event Emitter would be cleaned up by whichever plugin uses them, so there's no need to destroy it when destroying a Scene). The Systems object is rarely touched, so I doubt you've ended up doing something to it from your code, but I can't think of any other possibility.

I have absolutely been touching the data improperly then, let me adjust and report back. Maybe the two could be tied together? 

Thanks for the insight!

Share this post


Link to post
Share on other sites

The issue seems to be resolved! Thank you very much Telinc1 for your help.

I will say I do get the error:

WebGL: INVALID_OPERATION: bindTexture: attempt to bind a deleted texture

 but everything seems to be working regardless so I'll leave it alone unless you think its an issue waiting to happen.

Again, thank you very much for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.