Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'addEventListener' of null #7

Open
namel opened this issue Feb 15, 2017 · 3 comments
Open

Comments

@namel
Copy link
Member

namel commented Feb 15, 2017

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');
	                });
@alexus85
Copy link

alexus85 commented Sep 4, 2017

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#1

@OpherV
Copy link
Member

OpherV commented Sep 5, 2017

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

@stardust2005
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants