Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL Audio: playing audio in strict mode using audio element results in error when ended #21898

Open
sk-1982 opened this issue May 6, 2024 · 0 comments

Comments

@sk-1982
Copy link

sk-1982 commented May 6, 2024

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.59 (0e4c5994eb5b8defd38367a416d0703fd506ad81)
clang version 19.0.0git (https:/github.com/llvm/llvm-project df762a1643bb5b0b3c907611d118c82d4b68a39d)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: F:\Code\emsdk\upstream\bin

When emscripten is run in javascript strict mode (such as when STRICT_JS is enabled), and SDL audio is played using an audio element (such as preloaded audio with --use-preload-plugins), then the audio onended event attempts to set the read-only property paused of the audio element. This is not allowed in strict mode, and results in an error. As a result, the audio is not cleaned up and SDL will run out of channels.

Example code:

#include <SDL.h>
#include <SDL_mixer.h>
#include <emscripten/emscripten.h>

Mix_Chunk* chunk;

EMSCRIPTEN_KEEPALIVE void play_audio() {
	Mix_PlayChannel(-1, chunk, 0);
}

int main() {
	SDL_Init(SDL_INIT_AUDIO);
	Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 1, 1024);
	chunk = Mix_LoadWAV("test.wav");
	EM_ASM(document.querySelector('#canvas').addEventListener('click', () => Module._play_audio()));
}

Compiling with emcc main.c -s USE_SDL=1 --use-preload-plugins --preload-file=test.wav -o main.html and clicking the canvas does not result in an error, as emscripten is not in strict mode.

Compiling with emcc main.c -s USE_SDL=1 -s STRICT_JS --use-preload-plugins --preload-file=test.wav -o main.html and clicking the canvas results in Uncaught TypeError: setting getter-only property "paused" when the audio ends. Clicking enough times will eventually result in the error All 32 channels in use! being logged and no further audio can be played.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant