mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
3.96k stars 348 forks source link

EMSCRIPTEN - Aborted(Assertion failed: notification.pDevice != ((void*)0), at: #886

Closed MichealReed closed 1 month ago

MichealReed commented 1 month ago
Aborted(Assertion failed: notification.pDevice != ((void*)0), at:
minisound/minisound_ffi/src/external/miniaudio/src/miniaudio.c,7218,ma_device__on_notification)
RuntimeError: Aborted(Assertion failed: notification.pDevice != ((void*)0), at:
minisound/minisound_ffi/src/external/miniaudio/src/miniaudio.c,7218,ma_device__on_notification). Build with -sASSERTIONS for
more info.

I found a crash with the emscripten flow:

If I try to interact with the engine by playing a sound before the microphone notification has been triggered or before I interact once with the page, the error shows and the call to actually trigger the recording notification seems to crash.

If I click once in a random spot before trying to record (but before interacting with the engine otherwise after init and loading of a sound), it does not trigger this assertion. If I click to start recording immediately with this engine, it does not trigger the assertion. If the first click is to play a sound after my recorder has been created, the permission notification does not appear and the initialization call to the recorder crashes the whole engine.

I tried to build with -sASSERTIONS but I think it runs into a separate emscripten bug with ccall when this flag is enabled. The initialization logic is here: https://github.com/MichealReed/minisound/blob/f28148c7f33399e85cdb26afc0743c136e2158fd/minisound_ffi/src/src/record.c#L50

Aborted(Assertion failed: The call to engine_init is running asynchronously. If this was intended, add the async option to the ccall/cwrap
call.)
MichealReed commented 1 month ago

This would likely fix by initializing the capture device when the engine starts, but that would likely cause crashes in cases without a capture device, where only playback is desired.

mackron commented 1 month ago

Thanks. Are you able to check the dev branch? I wonder if this PR might fix this one: https://github.com/mackron/miniaudio/pull/888

MichealReed commented 1 month ago

Indeed looks fixed with that, thanks!!