charto / nbind

:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:
MIT License
1.98k stars 119 forks source link

Bug when building GLFW3 app with emscripten #62

Closed tyduptyler13 closed 7 years ago

tyduptyler13 commented 7 years ago

NBind seems to fail at runtime when using GLFW3 with emscripten. During testing I would get errors about Module["canvas"] being undefined.

I have fooled around a bit with the pre.js file and discovered two versions of Module floating around in the Object tree and the one attached to the window object has a canvas value. Copying this value to the Module passed to the nbind init seems to get passed this error but still runs into other errors. (I have yet to confirm that these errors are related to nbind at all)

The most important part of this is that static initialization of GLFW3 does not work with nbind and emscripten due to the way the Module object is passed around.

I can create a basic demo later to show you what is going on, if it is needed.

jjrv commented 7 years ago

Nbind will provide an empty Module object to the asm.js code unless you pass one as the first argument to init. It doesn't leak the variable from the asm.js wrapper scope, so if you have a custom Module object, passing it to init should make everything work as normal and not cause any problems.

The only thing is that if your own Module has an onRuntimeInitialized hook, it will be called before nbind_init and thus shouldn't try to make calls using wrappers defined using nbind.

tyduptyler13 commented 7 years ago

Thank you for the quick response. I will see what appending a custom module does after I reset the pre.js file to normal.

tyduptyler13 commented 7 years ago

So calling nbind like so seems to work properly, but now I have other problems I am still swimming around in. They are unrelated to the initial issue though. Thank you for your help.

nbind.init(Module, function(err, binding) { console.log(err, binding); });