ftsf / nico

a Game Framework in Nim inspired by Pico-8.
MIT License
624 stars 35 forks source link

Uncaught (in promise) TypeError: eventHandler.target is null #97

Closed iffy closed 1 year ago

iffy commented 1 year ago

I'm compiling with Nim 1.6.6 and Emscripten 3.1.19 with nimble webr and when I load it in Firefox I get this error in the console (and no game shows up):

Uncaught (in promise) TypeError: eventHandler.target is null
    registerOrRemoveHandler http://127.0.0.1:8090/carrider.js:1
    registerMouseEventCallback http://127.0.0.1:8090/carrider.js:1
    _emscripten_set_mousemove_callback_on_thread http://127.0.0.1:8090/carrider.js:1
    createExportWrapper http://127.0.0.1:8090/carrider.js:1
    callMain http://127.0.0.1:8090/carrider.js:1
    doRun http://127.0.0.1:8090/carrider.js:1
    run http://127.0.0.1:8090/carrider.js:1
    runCaller http://127.0.0.1:8090/carrider.js:1
    removeRunDependency http://127.0.0.1:8090/carrider.js:1
    receiveInstance http://127.0.0.1:8090/carrider.js:1
    receiveInstantiationResult http://127.0.0.1:8090/carrider.js:1
    promise callback*createWasm/instantiateAsync/< http://127.0.0.1:8090/carrider.js:1
    promise callback*instantiateAsync http://127.0.0.1:8090/carrider.js:1
    createWasm http://127.0.0.1:8090/carrider.js:1
    <anonymous> http://127.0.0.1:8090/carrider.js:1
Screen Shot 2022-08-18 at 10 15 20 PM

I'm about to try with earlier Emscripten versions to see if that's the reason. Do you happen to have a recommended Emscripten version?

iffy commented 1 year ago

I've tried these Emscripten versions with no luck: 3.1.19, 2.0.34, 1.39.20, 1.39.7, 1.40.1 Also tried Nim 1.4.0 but got the same error.

It's not my code (though it's probably something I'm doing wrong). Here's a fresh nicoboot-created repo that reproduces the error for me: https://github.com/iffy/nico-issue-97

Steps to duplicate:

git clone https://github.com/iffy/nico-issue-97.git
cd nico-issue-97
./buildindocker.sh

Then run a webserver (I did python -m http.server 8090 and browsed to http://127.0.0.1:8090)

iffy commented 1 year ago

By following what they did in https://github.com/emscripten-core/emscripten/issues/11295 I replaced all instances of nicogame with canvas in index.html and then got this error:

Uncaught (in promise) RuntimeError: Aborted(No EM_ASM constant found at address 18312)
    abort http://127.0.0.1:8090/app.js:1
    _emscripten_asm_const_int http://127.0.0.1:8090/app.js:1
    createExportWrapper http://127.0.0.1:8090/app.js:1
    callMain http://127.0.0.1:8090/app.js:1
    doRun http://127.0.0.1:8090/app.js:1
    run http://127.0.0.1:8090/app.js:1
    runCaller http://127.0.0.1:8090/app.js:1
    removeRunDependency http://127.0.0.1:8090/app.js:1
    receiveInstance http://127.0.0.1:8090/app.js:1
    receiveInstantiationResult http://127.0.0.1:8090/app.js:1
    promise callback*createWasm/instantiateAsync/< http://127.0.0.1:8090/app.js:1
    promise callback*instantiateAsync http://127.0.0.1:8090/app.js:1
    createWasm http://127.0.0.1:8090/app.js:1
    <anonymous> http://127.0.0.1:8090/app.js:1
ftsf commented 1 year ago

image

building this project using

. /path/to/emsdk/emsdk_env.sh
nimble webr
nimhttpd # to run the webserver

then going to localhost:1337/app.html works for me.

I'm not using docker to build it since I don't have docker. I am using EMSDK 2.0.13

Maybe it's not working because you're going to index.html rather than the html file generated from your app. The app should probably be generated to index.html instead of <appname>.html

iffy commented 1 year ago

YES, thank you! I was looking at index.html instead of <appname>.html