Jump to content

Error happens after state restart


Puflo
 Share

Recommended Posts

I have 2 states: Game and Idle, i switch state to Idle everytime player disconnects from the server, and state is switched to Game when player connects to a server.

I get this error after restarting game state without refreshing the page:

Quote

Uncaught TypeError: Cannot read property 'world' of null
    at Phaser.TilemapLayer.resizeWorld (phaser.js:101396)
    at default.<anonymous> (Game.js:36)
    at Phaser.SignalBinding.execute (phaser.js:30147)
    at Phaser.Signal.dispatch (phaser.js:29952)
    at Phaser.ScaleManager.signalSizeChange (phaser.js:82224)
    at Phaser.ScaleManager.preUpdate (phaser.js:82304)
    at Phaser.Game.updateLogic (phaser.js:36167)
    at Phaser.Game.update (phaser.js:36114)
    at Phaser.RequestAnimationFrame.updateRAF (phaser.js:64223)
    at _onLoop (phaser.js:64206)

This SignalBinding causes the error

this.scaleSignal = this.scale.onSizeChange.add(function(scaleObject, width, height){
	if (this.map && this.collisionLayer && this.tileLayer){
		this.collisionLayer.resize(width, height);
		this.tileLayer.resize(width, height);
		this.tileLayer.resizeWorld();
	}
}, this);

I have this shutdown function to prevent it, but the error still occurs.

shutdown(){
    console.log('Game state is shutting down');
    this.scaleSignal.detach();
}

Why is this happening and how can i fix it?

Link to comment
Share on other sites

13 hours ago, samme said:

It does seem that detach should avoid that.

Are this.scaleSignal and this.tileLayer assigned at about the same time?

No, scaleSignal is assigned before tileLayer. This error only happens after restart even if i don't resize the game.

Link to comment
Share on other sites

On 14.04.2018 at 6:27 PM, samme said:

Is it possible that the "new" onSizeChange handler (not the "old" handler that failed to detach) is getting called before a "new" tileLayer is assigned?

You can add in shutdown


this.tileLayer = null;

and see if the error changes.

Sorry for late response. That fixed the problem.

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...