spaaace icon indicating copy to clipboard operation
spaaace copied to clipboard

Uncaught TypeError: Cannot read property 'addEventListener' of null

Open namel opened this issue 8 years ago • 3 comments

This happens when I start running spaaace on a computer where it never ran before, so it is fixed by refreshing the page.

When it happens, the game doesn't start. The exception is raised on the SpaaaceClientEngine::start() method, in the third line below:

	            this.gameEngine.once('renderer.ready', function () {
	                // click event for "try again" button
	                document.querySelector('#tryAgain').addEventListener('click', function () {
	                    if (Utils.isTouchDevice()) {
	                        _this2.renderer.enableFullScreen();
	                    }
	                    _this2.socket.emit('requestRestart');
	                });

namel avatar Feb 15 '17 11:02 namel

That's probably because the element hadn't been loaded at the time when the bundle js was being executed.

I'd move the <script src="dist/bundle.js" type="text/javascript"></script> to the very bottom of the index.html file. This way you can ensure script is executed after all the html elements have been parsed and rendered .

alexus85/spaaace#1

alexus85 avatar Sep 04 '17 07:09 alexus85

Yep, that's a good notion in general. I'm in the process of re-writing spaaace for Lance V2 and that'll definitely get sorted out there soon :)

OpherV avatar Sep 05 '17 07:09 OpherV

Thank you very much, alexus85 . Yesterday I spent the whole day trying to figure out what was going on in my code, where the mistake was. In the end, it was only the position of the script within the html file.

Thank you very much for bringing me the solution.

https://github.com/alexus85

stardust2005 avatar Apr 20 '18 07:04 stardust2005