Fix web: don't spawn the deferred-pause std::thread on web (Aborted() in initEngine)#488
Conversation
…orted in initEngine) 4.0.10 added a background pause-scheduler thread that `Player::init()` starts unconditionally via `startPauseEngineScheduler()`. On web the wasm is built single-threaded (compile_wasm.sh passes no -pthread), so constructing `std::thread` calls `pthread_create` with no thread runtime and the module aborts: `RuntimeError: Aborted()` inside initEngine — every web user crashes the moment the engine initializes. This guards the thread machinery with `__EMSCRIPTEN__`: - `startPauseEngineScheduler()` / `stopPauseEngineScheduler()` become no-ops on web (no thread is ever constructed). - `pauseEngine()` falls back to the pre-4.0.10 behavior on web — pause the device immediately when no voices remain active. The browser's AudioContext doesn't have the OS audio-session settling issue that motivates the delay on iOS/native, so the immediate pause is correct there. Native (iOS/Android/desktop) keeps the deferred, coalesced pause unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Runtime verification (real browser)I rebuilt the web wasm from this branch with Emscripten 6.0.0 and ran
So the Still source-only here — the committed |
…it-thread fix Rebuilt via web/compile_wasm.sh (Emscripten 6.0.0, with Opus/Ogg) so the __EMSCRIPTEN__ guard is reflected in the published web artifacts. Verified in Chrome: initEngine returns 0 / isInited() == 1 (no Aborted()). Note: built with emsdk 6.0.0 — if you release with a different Emscripten version, regenerate with yours so the binary diff matches your toolchain. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thank you so much! LGTM.
Thanks, I will rebuild wasm before publishing on pub.dev. |
Description
On web,
SoLoud.init()aborts withRuntimeError: Aborted()insideinitEngineas soon as the engine initializes — a regression in 4.0.10.4.0.10 (#486) starts a background pause-scheduler thread in
Player::init()(startPauseEngineScheduler()→std::thread). The web build is single-threaded (web/compile_wasm.shpasses no-pthread), so constructingstd::threadcallspthread_createwith no thread runtime and the module aborts on the firstinit(). 4.0.9 had no such thread.This guards the thread behind
__EMSCRIPTEN__:startPauseEngineScheduler()/stopPauseEngineScheduler()are no-ops on web (nostd::threadis constructed).pauseEngine()falls back to the pre-4.0.10 immediate pause on web — the browser's AudioContext doesn't have the OS audio-session settling issue that motivates the delay on native.Native (iOS/Android/desktop) keeps the deferred, coalesced pause unchanged.
The web artifacts (
web/libflutter_soloud_plugin.{js,wasm}) are regenerated viaweb/compile_wasm.sh(Emscripten 6.0.0, with Opus/Ogg) and committed.Verified in Chrome with the rebuilt artifacts by calling
initEngine:Aborted(). Build with -sASSERTIONS for more info.(the crash)initEnginereturns0,isInited()returns1— no abortType of Change