Skip to content

Cube WASM demo doesn't run #227

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

Closed
GoJermangoGo opened this issue Jan 8, 2019 · 10 comments
Closed

Cube WASM demo doesn't run #227

GoJermangoGo opened this issue Jan 8, 2019 · 10 comments

Comments

@GoJermangoGo
Copy link
Contributor

I tried out this demo in Chrome and I can only see the floor plane.

Console log:

@shawn0326
Copy link

same to me

@GoJermangoGo
Copy link
Contributor Author

It seems like it's actually an emscripten bug. Someone had an almost identical error while trying to compile OpenCV. (emscripten-core/emscripten#7562, see most recent comment)

I was able to get it working by compiling with emscripten 1.38.12. Any version after that either fails to compile or gives the above error in Chrome.
(I had to undo the DebugDrawer commit d144e11 to avoid emscripten-core/emscripten#7234, which hadn't been merged yet in the older version of emscripten)

@InfiniteLee
Copy link
Contributor

I've spent the entire day trying to figure out what's happening here, but the only way I can get a working wasm build is if I do what @luisfonsivevo did with the exception that I was able to compile with 1.38.13.
Also I discovered that if you just comment out

[JSImplementation="btIDebugDraw"]
interface DebugDrawer {
...
}

you can avoid the error in the wasm build. This led me to believe that it was an issue with JSImplementation and wasm, but the same trick doesn't work for emscripten > 1.38.13 so not sure).

All my googling makes me think there is some memory related wasm configuration that is not correct for ammo.js, but I'm not sure.

Whatever it is, it seems like the wasm builds have just been broken for the past couple of months, starting around when the DebugDrawer stuff was added. However, even if I go to an ammo.js version prior to that and try to build with emscripten > 1.38.13, the wasm build has the same errors. This leads me to believe that something in 1.38.14 broke wasm for ammo.js. Any ideas @kripken?

@InfiniteLee
Copy link
Contributor

InfiniteLee commented Jan 17, 2019

Well I just had revelation: That specific example is using an ammo.wasm.wasm build that is a year old. If you copy the new ammo.wasm.wasm build from the builds directory over it, it works fine. That old one is just obviously not compatible with the new wasm builds that have been made in the past few months.

I think there's a separate issue where the .wasm file doesn't get loaded correctly depending on browser/how your web server is setup, which is probably why this example has it sitting right next to the example's html file.

@kripken
Copy link
Owner

kripken commented Jan 17, 2019

I think there's a separate issue where the .wasm file doesn't get loaded correctly depending on browser/how your web server is setup, which is probably why this example has it sitting right next to the example's html file.

Might have been an issue with older emscripten versions. Perhaps now we can just make it point to the build dir and get the wasm and js there.

@GoJermangoGo
Copy link
Contributor Author

Looks like the January 15 build did indeed fix it. Previously, the demo, the October 25 build, and anything I tried to build on my own web server were all giving the same error. I'm able to compile it now with emscripten 1.38.24. Just have to update the demo website now.

@InfiniteLee
Copy link
Contributor

Might have been an issue with older emscripten versions. Perhaps now we can just make it point to the build dir and get the wasm and js there.

Sorry this should probably be in a new issue for emscripten, but I think the larger issue is that it is difficult to use wasm binaries with webpack right now unless you use some workarounds. E.g. this seems to work (taken from https://gist.github.com/surma/b2705b6cca29357ebea1c9e6e15684cc):

const OriginalAmmo = require("ammo.js/builds/ammo.wasm.js");
//uses webpack file loader to get the relative path of the wasm binary
const WasmBinaryPath = require("ammo.js/builds/ammo.wasm.wasm");
const Ammo = OriginalAmmo .bind(undefined, {
  locateFile(path) {
    if (path.endsWith(".wasm")) {
      return WasmBinaryPath ;
    }
    return path;
  }
});

This is not an issue for simple projects like the ammo examples which can use script tags, but for projects that try to use ammo as an npm dependency (or for that matter, a dependency of a dependency).

That said, I believe the long term solution is to have a real ES module target for Ammo.js, which would require updating emscripten, specifically preamble.js, such that webpack is responsible for creating the wasm module given the url to the wasm binary in an import statement like what is proposed here: webpack/webpack#7352 (comment)

When https://github.com/WebAssembly/esm-integration lands, the preamble.js will likely be able to go away and the wasm binary will be able to be imported via the same ESM syntax.

@kripken
Copy link
Owner

kripken commented Jan 18, 2019

Emscripten does has ES6 module support, with EXPORT_ES6. It's not tested much yet, though, because it was waiting on VM support, but maybe that's present now? Worth experimenting if someone has time.

@kripken
Copy link
Owner

kripken commented Jan 18, 2019

There is also .mjs suffix support which auto-enables that option, emscripten-core/emscripten#7876

kripken pushed a commit that referenced this issue Jan 28, 2019
* updated builds with emscripten 1.38.25

May help with #227
@GoJermangoGo
Copy link
Contributor Author

Works now

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