Slightly off-topic (and a shameless plug), but you if you're looking for an 
absolutely minimalistic GLFW alternative you should check out the 
sokol-headers, specifically sokol_app.h:

https://github.com/floooh/sokol#sokol_apph

It's all still work in progress, but definitely good enough already for 
small demos like this:

https://floooh.github.io/sokol-html5/

Here's more sample source code:

https://github.com/floooh/sokol-samples/tree/master/sapp

The 'tiny emulators' here are using all the sokol headers (they're 
rendering through WebGL, even though it's just simple 2D stuff):

https://floooh.github.io/tiny8bit/

Cheers!
-Floh.

On Thursday, 30 August 2018 03:50:30 UTC+2, Andrew wrote:
>
> I posted the solution here on stackoverflow,
>
> https://stackoverflow.com/questions/52077995/basic-setup-for-glfw-causes-a-runtime-error-with-regards-to-eventlistener-in-ems
>  if anyone wants to explain why the solution is slightly different from 
> the question feel free to.
>
> On Wednesday, August 29, 2018 at 12:07:17 AM UTC-5, Andrew wrote:
>>
>> Hello everyone, 
>>
>> To make a long story short I tried to create the simplest possible setup 
>> for a an opengl c++ demo and the problem I have seems to be related to the
>> the initialization of the canvas with regards to the eventlistener that 
>> is found in the javascript wrapper for the wasm file. I'm new to this so 
>> I'll just post 
>> the code in cpp, the html file, and the command line used to compile the 
>> project plus the error in chromium.
>>
>> This is the glfw.cpp
>>
>> #include <emscripten/emscripten.h>
>> #include <emscripten/bind.h>
>> using namespace emscripten;
>>
>> #define GLFW_INCLUDE_ES3
>>
>> #include <GLFW/glfw3.h>
>> #include <GLES3/gl3.h>
>>
>>
>> void initialize()
>> {
>>  // Initialise GLFW
>> if( !glfwInit() )
>> {
>> EM_ASM_({
>>   console.log(' failed: ');
>> }, 0); 
>> }
>>
>> EM_ASM_({
>>   console.log(' end initialization: ');
>> }, 0); 
>> }
>> EMSCRIPTEN_BINDINGS(glfw) 
>> {   
>>     function("initialize", &initialize);
>> }
>>
>>
>> This is the glfw.html
>>
>> <!doctype html>
>> <html> 
>> <head>
>> </head>
>> <body>
>> <canvas id="canvas" oncontextmenu="event.preventDefault()" style = 
>> "height: 100%; width: 100%; background-color:red;"></canvas>
>> <script> 
>> var Module = 
>> {
>> canvas: function() 
>> {
>> console.log("canvas");
>> var canvas = document.getElementById('canvas');
>> canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL 
>> context lost. You will need to reload the page.'); e.preventDefault(); }, 
>> false);
>>
>> return canvas;
>> },
>> onRuntimeInitialized: function() 
>> {
>> Module.initialize();
>> } 
>> }; 
>> </script>
>> <script type="text/javascript" src="glfw.js"> </script> 
>> </body>
>> </html>
>>
>>
>> the command to compile the project
>>
>> emcc --bind -o glfw.js glfw.cpp -s USE_GLFW=3 
>>
>> and this is the complete error from the console.log in chromium
>>
>> glfw.js:1645 Fetch finished loading: GET "http://localhost:8080/glfw.wasm
>> ".
>> doNativeWasm @ glfw.js:1645
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:1650 wasm streaming compile failed: TypeError: 
>> Module.canvas.addEventListener is not a function
>> (anonymous) @ glfw.js:1650
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:1651 falling back to ArrayBuffer instantiation
>> (anonymous) @ glfw.js:1651
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:1560 Fetch finished loading: GET "http://localhost:8080/glfw.wasm
>> ".
>> getBinaryPromise @ glfw.js:1560
>> instantiateArrayBuffer @ glfw.js:1633
>> (anonymous) @ glfw.js:1652
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:5228 Assertion failed: the Module object should not be replaced 
>> during async compilation - perhaps the order of HTML elements is wrong?
>> glfw.js:5229 Assertion failed: the Module object should not be replaced 
>> during async compilation - perhaps the order of HTML elements is wrong?
>> abort @ glfw.js:5229
>> assert @ glfw.js:434
>> receiveInstantiatedSource @ glfw.js:1628
>> Promise.then (async)
>> instantiateArrayBuffer @ glfw.js:1635
>> (anonymous) @ glfw.js:1652
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:1636 failed to asynchronously prepare wasm: abort("Assertion 
>> failed: the Module object should not be replaced during async compilation - 
>> perhaps the order of HTML elements is wrong?") at Error
>>     at jsStackTrace (http://localhost:8080/glfw.js:1033:13)
>>     at stackTrace (http://localhost:8080/glfw.js:1050:12)
>>     at abort (http://localhost:8080/glfw.js:5239:44)
>>     at assert (http://localhost:8080/glfw.js:434:5)
>>     at receiveInstantiatedSource (http://localhost:8080/glfw.js:1628:7)
>> (anonymous) @ glfw.js:1636
>> Promise.catch (async)
>> instantiateArrayBuffer @ glfw.js:1635
>> (anonymous) @ glfw.js:1652
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.js:5228 abort("Assertion failed: the Module object should not be 
>> replaced during async compilation - perhaps the order of HTML elements is 
>> wrong?") at Error
>>     at jsStackTrace (http://localhost:8080/glfw.js:1033:13)
>>     at stackTrace (http://localhost:8080/glfw.js:1050:12)
>>     at abort (http://localhost:8080/glfw.js:5239:44)
>>     at assert (http://localhost:8080/glfw.js:434:5)
>>     at receiveInstantiatedSource (http://localhost:8080/glfw.js:1628:7)
>> glfw.js:5229 abort("Assertion failed: the Module object should not be 
>> replaced during async compilation - perhaps the order of HTML elements is 
>> wrong?") at Error
>>     at jsStackTrace (http://localhost:8080/glfw.js:1033:13)
>>     at stackTrace (http://localhost:8080/glfw.js:1050:12)
>>     at abort (http://localhost:8080/glfw.js:5239:44)
>>     at assert (http://localhost:8080/glfw.js:434:5)
>>     at receiveInstantiatedSource (http://localhost:8080/glfw.js:1628:7)
>> abort @ glfw.js:5229
>> (anonymous) @ glfw.js:1637
>> Promise.catch (async)
>> instantiateArrayBuffer @ glfw.js:1635
>> (anonymous) @ glfw.js:1652
>> Promise.catch (async)
>> doNativeWasm @ glfw.js:1647
>> Module.asm @ glfw.js:1735
>> (anonymous) @ glfw.js:4813
>> glfw.html:1 Uncaught (in promise) abort("abort(\"Assertion failed: the 
>> Module object should not be replaced during async compilation - perhaps the 
>> order of HTML elements is wrong?\") at Error\n    at jsStackTrace (
>> http://localhost:8080/glfw.js:1033:13)\n    at stackTrace (
>> http://localhost:8080/glfw.js:1050:12)\n    at abort (
>> http://localhost:8080/glfw.js:5239:44)\n    at assert (
>> http://localhost:8080/glfw.js:434:5)\n    at receiveInstantiatedSource (
>> http://localhost:8080/glfw.js:1628:7)") at Error
>>     at jsStackTrace (http://localhost:8080/glfw.js:1033:13)
>>     at stackTrace (http://localhost:8080/glfw.js:1050:12)
>>     at abort (http://localhost:8080/glfw.js:5239:44)
>>     at http://localhost:8080/glfw.js:1637:9
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to