What I’m trying to do
I’m trying to build mujoco (a native c++ physics library) into a Unity WebGL build. Fortunately, mujoco comes with a Unity plugin; however, the package relies on a DLL, which cannot be used in web builds. To get around this, I’ve tried pre-compiling the mujoco library from source via emscripten into static library .a files, which is what the Unity docs recommend. I made sure to use the correct emscripten version as well. I place the .a files into my plugins folder under assets, and mujoco has a bindings script that links itself to the .a files. In theory, this should be buildable for WebGL.
Versions I’m using
Unity 2022.3.27f1
Emscripten 3.1.8
Mujoco 3.1.1
The error
Here’s the error I get after the WebGL build fails:
Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
wasm-ld: warning: function signature mismatch: mjv_averageCamera
>>> defined as (i32, i32) -> i32 in C:/Users/winster/projects/MujocoNewEmsdk/Library/Bee/artifacts/WebGL/il2cppOutput/build/GameAssembly.a(09gffyudb6z8.o)
>>> defined as (i32, i32, i32) -> void in Assets/Plugins/build2/lib/libmujoco.a(engine_vis_interact.c.o)
wasm-ld: warning: function signature mismatch: mjr_maxViewport
>>> defined as (i32) -> i32 in C:/Users/winster/projects/MujocoNewEmsdk/Library/Bee/artifacts/WebGL/il2cppOutput/build/GameAssembly.a(09gffyudb6z8.o)
>>> defined as (i32, i32) -> void in Assets/Plugins/build2/lib/libmujoco.a(render_gl2.c.o)
wasm-ld: warning: function signature mismatch: mjui_themeColor
>>> defined as (i32) -> i32 in C:/Users/winster/projects/MujocoNewEmsdk/Library/Bee/artifacts/WebGL/il2cppOutput/build/GameAssembly.a(09gffyudb6z8.o)
>>> defined as (i32, i32) -> void in Assets/Plugins/build2/lib/libmujoco.a(ui_main.c.o)
[parse exception: attempted pop from empty stack / beyond block start boundary at 8986318 (at 0:8986318)]
Fatal: error in parsing input
emcc: error: '"C:/Program Files/Unity/Hub/Editor/2022.3.27f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/binaryen\bin\wasm-emscripten-finalize" -g Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm -o Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm --detect-features' failed (returned 1)
What I’ve tried
I’ve been able to fix the signature mismatches by manually editing them in the mujoco bindings script. However, the ```
[parse exception: attempted pop from empty stack / beyond block start boundary at 8986318 (at 0:8986318)]
Fatal: error in parsing input
I'd be more than happy to post any additional information or stack traces. I know this is pretty niche, so any feedback would be super helpful!