Open ad8e opened 1 year ago
This might also make sense in an FAQ entry, as it is not specific to wasm workers - it also happens with pthreads. An FAQ entry about what to do with the SharedArrayBuffer is not defined
error might be best.
Also there might be good docs for that elsewhere on the web, that show up when you search that question, which we could link to from our docs.
Better still we could show a message in debug builds when SharedArrayBuffer
is not available. We already do this in certain place(s). e.g.: https://github.com/emscripten-core/emscripten/blob/00eae746d233099faccc299dd3abc86ae834f837/src/runtime_init_memory.js#L51-L59
We should probably add a generic/central test up front and report consistently on all builds that depend on shared memory
https://github.com/emscripten-core/emscripten/issues/20349#issuecomment-1762155539 encountered problems with SharedArrayBuffer. Neither of the tutorials mentions CORS, so this was an inevitable error: https://emscripten.org/docs/api_reference/wasm_audio_worklets.html, https://github.com/emscripten-core/emscripten/blob/main/test/webaudio/audioworklet.c.
Proposed solution: Add docs. At https://emscripten.org/docs/api_reference/wasm_audio_worklets.html, right after "Compile the code with the linker flags -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 to enable targeting AudioWorklets.", this text is added:
"Web browsers prohibit sharing data between threads unless CORS headers are set. If you try to open the html file you just compiled, you will receive the error
SharedArrayBuffer is not defined
. To fix this, host the html file with a web server that sets CORS headers. For example, you can runpython3 \[this python script\]
to serve all files in the same directory, then navigate to http://127.0.0.1:8000/your_file_here.html. See MDN for more information."The python script is this one. The extension should be .py; github doesn't let me upload .py files.