-
Notifications
You must be signed in to change notification settings - Fork 13
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
WebAssembly (wasm) target support, faster/smaller than asm.js #1
Comments
Adding -s WASM to CMakeFiles.txt LINK_FLAGS, it builds but cannot test locally due to promise fetch API: craft.js:1806 Fetch API cannot load file:////NetCraft/build/craft.wasm. URL scheme must be "http" or "https" for CORS request. run from a local server: python -m SimpleHTTPServer then http://localhost:8000/craft.html - this works in Chrome 57.0.2987.133, and seems snappier. The wasm build output with emscripten is a lot smaller:
than the asm.js emscripten output:
1.1M + 2.6M = 3.7M for wasm vs 14M for asm.js. But the downside is less browser compatibility, just hangs in Safari Technical Preview. So the asm.js-based emscripten build would still be needed. Question now is how to integrate this variant into the build system. Make it a cmake option (to add to the arguments of |
Added for GH-45 and this a wasm build type: mkdir wasm-build
cmake -DWASM=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ..
make However, wasm used to work, when I first tried it -- but now, get an out-of-memory access?! craft.html:1251 exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds What changed? Need to regress to 4/4, isolate cp CMakeLists.txt /tmp git checkout CMakeLists.txt cd wasm-build works: fails to compile (missing conditional compilation for web):
broken (memory access out of bounds error): so it's something from aa99147 or 999ac5e? Wouldn't have expected it... Starting with aa99147 and commenting out native calls so it compiles: --- a/src/main.c
+++ b/src/main.c
@@ -2430,13 +2430,13 @@ void get_fullscreen_monitor_dimensions() {
}
void fullscreen_exit() {
- glfwSetWindowMonitor(g->window, NULL, g->window_xpos, g->window_ypos, g->window_width, g->window_height, GLFW_DONT_CARE);
+ //glfwSetWindowMonitor(g->window, NULL, g->window_xpos, g->window_ypos, g->window_width, g->window_height, GLFW_DONT_CARE);
}
void fullscreen_enter() {
glfwGetWindowPos(g->window, &g->window_xpos, &g->window_ypos);
glfwGetWindowSize(g->window, &g->window_width, &g->window_height);
- glfwSetWindowMonitor(g->window, g->fullscreen_monitor, 0, 0, g->fullscreen_width, g->fullscreen_height, GLFW_DONT_CARE);
+ //glfwSetWindowMonitor(g->window, g->fullscreen_monitor, 0, 0, g->fullscreen_width, g->fullscreen_height, GLFW_DONT_CARE);
}
void create_window() { wasm does crash with RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds, so, it is something added in this commit Found it: get_fullscreen_monitor_dimensions(). This calls glfwGetPrimaryMonitor() and indexes the video modes array, certainly not needed for the web. The variables it sets weren't being used on the web (native only, where there are monitors) so execution was harmless except for the out-of-bounds memory accesses it caused. |
Build for wasm in addition to asm.js, expected faster but less compatible (requires prerelease browsers at the time of this writing). Build for both and let the user choose, or fallback automatically.
Add
-s WASM=1
to emcc, and BINARYEN_METHOD native-wasm and/or asmjs, refer to: https://github.com/kripken/emscripten/wiki/WebAssemblyThe text was updated successfully, but these errors were encountered: