emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.92k stars 3.32k forks source link

emscripten_start_wasm_audio_worklet_thread_async is not helpful when it fails #21178

Open akpmilot opened 10 months ago

akpmilot commented 10 months ago

The Javascript implementation of emscripten_start_wasm_audio_worklet_thread_async does not print the reason for failure when calling the callback with success=false. This makes it very difficult to understand why processor creation fails.

As of this writing, the current implementation looks like this:

      let audioWorkletCreationFailed = () => {
        getWasmTableEntry(callback)(contextHandle, 0/*EM_FALSE*/, userData);
      };

      // [...]

      audioWorklet.addModule('IntegrationDemo.aw.js').then(() => {
          // [...]
      }).then(() => {
        getWasmTableEntry(callback)(contextHandle, 1/*EM_TRUE*/, userData);
      }).catch(audioWorkletCreationFailed); // <-- Error object is dropped here

In my case, it was failing because my C++ code had a EM_ASM block containing Javascript that did not validate in strict mode. Specifically, the SyntaxError: applying the 'delete' operator to an unqualified name is deprecated was being thrown and caught by the above code, but never printed. I could not figure it out until I started modifying the javascript file generated by Emscripten.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.52 (fa478400df3351f7153c0279bc638784d3d90334)
clang version 18.0.0git (https://github.com/llvm/llvm-project 0a3a0ea5914cb4633f4f4c14f1ddc46ce067061a)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\emsdk\upstream\bin

Full link command and output with -v appended:

C:\emsdk\upstream\emscripten\em++.bat -o "../../../Emscripten_mt/Debug/bin/IntegrationDemo/IntegrationDemo.html" @linkargs.make  -L../../../Emscripten_mt/lib -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -Wl,--export-dynamic -pthread -g -sSTACK_OVERFLOW_CHECK=1 -sUSE_SDL=2 -sEXPORTED_RUNTIME_METHODS=['err'] -sTOTAL_STACK=131072 -sPTHREAD_POOL_SIZE=15 -sTOTAL_MEMORY=134217728 --preload-file ../WwiseProject/GeneratedSoundBanks/Web@/GeneratedSoundBanks/Web -Wl,--start-group [REDACTED LIST OF IN-HOUSE LIBS] -Wl,--end-group
sbc100 commented 10 months ago

@juj ?