-
Earlier, I have successfully integrated a single-threaded emscripten-based WASM app in a React application (invoking the WASM app(Module) from a useEffect() call). Rendering works on the canvas as expected. After switching on multi-threading (-pthread, PROXY_TO_PTHREAD, OFFSCREENCANVAS_SUPPORT) for accelerated rendering, the app still starts when viewing it via a hand-crafted index.html that includes app.js, defines the Module and its canvas and calls the app(Module)... and the canvas gets filled as expected. However with multi-threading the exact same code does not work in a React application in a startup useEffect() call results in an error event "Pthread 0x01519128 sent an error! undefined:undefined: undefined" triggered in loadWasmModuleToWorker. Interestingly, when compiling the app even with a minimum thread pool size of two "SHELL:-s PTHREAD_POOL_SIZE=2", the app does not start at all: "waiting for dependencies, dependencies: workers" is repeated every couple of seconds in the console. Any hints how to solve this issue or ideas how this happens? It seems strange to me since React does not do anything with threads. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
Beta Was this translation helpful? Give feedback.
Update: When placing a second copy of app.js not only for bundling, but also in react's public directory for being used by the WebWorker initialization and defining its name in the Module definition as mainScriptUrlOrBlob, the app is running.
Obviously this is not clean since the main app() function initializing the module is downloaded twice, once in the code of the bundler for react (vite / webpack) and once for the worker from it's vanilla emcc output app.js. I have seen that Blobs can also be passed as URL to workers, but the Blob also needs to include the whole code of app.js, correct?