erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.36k stars 1.55k forks source link

Add pthread support for Emscripten build. #841

Open aleph1 opened 1 week ago

aleph1 commented 1 week ago

When trying to load the built .js and .wasm files in current browsers (Chrome, Safari, Firefox), an error is triggered relating to pthreads. Adding the compiler and linker flags for Emscripten resolve the issue.

Chrome provides the most detailed error, and it is related to the TaskScheduler and pthread use:

test.js:546 Aborted(native code called abort()) test.js:564 Uncaught (in promise) RuntimeError: Aborted(native code called abort()) at abort (http://localhost:3000/js/test.js:564:11) at __abort_js (http://localhost:3000/js/test.js:1060:7) at test.wasm.abort (http://localhost:3000/js/test.wasm:wasm-function[1175]:0xdb538) at test.wasm.std::2::throw_system_error(int, char const*) (http://localhost:3000/js/test.wasm:wasm-function[1180]:0xdb60f) at test.wasm.std::__2::thread::thread<void (&)(enki::ThreadArgs const&), enki::ThreadArgs, void>(void (&)(enki::ThreadArgs const&), enki::ThreadArgs&&) (http://localhost:3000/js/test.wasm:wasm-function[885]:0xca7b9) at test.wasm.enki::TaskScheduler::StartThreads() (http://localhost:3000/js/test.wasm:wasm-function[877]:0xc9c89) at test.wasm.enki::TaskScheduler::Initialize(enki::TaskSchedulerConfig) (http://localhost:3000/js/test.wasm:wasm-function[967]:0xd0794) at test.wasm.enkiInitTaskSchedulerWithConfig (http://localhost:3000/js/test.wasm:wasm-function[1044]:0xd3a59) at test.wasm.TiltedStacks (http://localhost:3000/js/test.wasm:wasm-function[21]:0x3bcc) at test.wasm.MultithreadingTest (http://localhost:3000/js/test.wasm:wasm-function[19]:0x2321)