changeset 2664:36ae207af490

Awful hack to work around what seems like a bug in the Emscripten version of SDL2
author Michael Pavone <pavone@retrodev.com>
date Thu, 06 Mar 2025 01:47:49 -0800
parents 568c1c22f3e3
children 54ac5fe14cf9
files render_sdl.c
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/render_sdl.c	Thu Mar 06 01:33:03 2025 -0800
+++ b/render_sdl.c	Thu Mar 06 01:47:49 2025 -0800
@@ -1403,6 +1403,23 @@
 }
 static int in_toggle;
 
+#ifdef __EMSCRIPTEN__
+void resume_config_update(void *arg)
+{
+	uint8_t was_paused = arg != NULL;
+	quitting = 0;
+	init_audio();
+	render_set_video_standard(video_standard);
+
+	drain_events();
+	in_toggle = 0;
+	if (!was_paused) {
+		SDL_PauseAudio(0);
+	}
+	emscripten_resume_main_loop();
+}
+#endif __EMSCRIPTEN__
+
 void render_config_updated(void)
 {
 	for (int i = 0; i <= FRAMEBUFFER_UI; i++)
@@ -1479,8 +1496,13 @@
 	if (do_audio_reinit) {
 		was_paused = SDL_GetAudioStatus() == SDL_AUDIO_PAUSED;
 		render_close_audio();
+#ifdef __EMSCRIPTEN__
+		emscripten_pause_main_loop();
+		emscripten_async_call(resume_config_update, was_paused ? config : NULL, 1000);
+#else
 		quitting = 0;
 		init_audio();
+#endif
 	}
 	render_set_video_standard(video_standard);