Puflo Posted April 13, 2018 Share Posted April 13, 2018 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 More sharing options...
samme Posted April 13, 2018 Share Posted April 13, 2018 It does seem that detach should avoid that. Are this.scaleSignal and this.tileLayer assigned at about the same time? Link to comment Share on other sites More sharing options...
Puflo Posted April 14, 2018 Author Share Posted April 14, 2018 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 More sharing options...
samme Posted April 14, 2018 Share Posted April 14, 2018 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. Puflo 1 Link to comment Share on other sites More sharing options...
Puflo Posted April 16, 2018 Author Share Posted April 16, 2018 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 More sharing options...
Recommended Posts