emscripten-core / emscripten-core/emscripten

executing es6 imported Module function for audioworklet in non-cross-origin-isolated environment results in js error

Open
#22,191 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
```

I am building with the following flags:
```
-sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,callMain,addFunction,removeFunction -sEXPORT_ES6=1 -sMODULARIZE=1 -sALLOW_MEMORY_GROWTH=1 -sALLOW_TABLE_GROWTH=1
```

And when I attempt to call the `Module()` function, it is blowing up with:
```
ReferenceError: SharedArrayBuffer is not defined
at emulator.js:345:38
at (index):22:7
```

This comes from the code that is attempting to reference SharedArrayBuffer:
```
345 if (!(wasmMemory.buffer instanceof SharedArrayBuffer)) {
346 err("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has S
347 if (ENVIRONMENT_IS_NODE) {
348 err("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)");
349 }
350 throw Error("bad memory");
351 }
352 }
```

I don't know if this is considered desired behavior? Am I supposed to not attempt to instantiate that `Module` function if `crossOriginIsolated === false` ?

I also was wondering if there is any way to tell emscripten to not use the SharedArrayBuffer for web audio?

I found that google has a [sample webaudio + webassembly project](https://github.com/GoogleChromeLabs/web-audio-samples/blob/main/src/audio-worklet/design-pattern/wasm/wasm-worklet-processor.js) that uses an audioworklet without requiring `crossOriginIsolated` .. But they are not using any of the `emscripten_create_wasm_audio_worklet_node` or `emscripten_create_wasm_audio_worklet_processor_async` that I am, rather, they are manually building the audio context and using a .js class for their worklet class... So I was wondering if there's any way to still leverage emscripten to use c++ for setting up audio context + worklets but not be required to have those headers set?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.