Jump to content

Error happens after state restart


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:


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);

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

    console.log('Game state is shutting down');

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


  • Recently Browsing   0 members

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