From 80988e52cf680a39de93dd5c84c3cc1aa2a5a69a Mon Sep 17 00:00:00 2001 From: kichikuou Date: Wed, 27 Nov 2024 09:05:06 +0900 Subject: [PATCH] emscripten: Restore a hack to asyncify send_agsevent() callers It was inadvertently removed in commit 61ad428. --- src/CMakeLists.txt | 3 +++ src/sdl_event.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 556472e..1bd2667 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -162,6 +162,9 @@ if (EMSCRIPTEN) -sASYNCIFY_IGNORE_INDIRECT=1 -sASYNCIFY_REMOVE=SDL_Delay -sASYNCIFY_IMPORTS=wait_vsync + # Functions that call an asynchronous function via a function pointer must + # be added to ASYNCIFY_ADD, even if it had a direct call to another + # asynchronous function, so that the indirect call itself is instrumented. -sASYNCIFY_ADD=commands2F60,nact_main,send_agsevent,cb_waitkey_sprite -sALLOW_MEMORY_GROWTH=1 -sNO_EXIT_RUNTIME=1 diff --git a/src/sdl_event.c b/src/sdl_event.c index 5c0fed8..23c232f 100644 --- a/src/sdl_event.c +++ b/src/sdl_event.c @@ -222,6 +222,13 @@ void send_agsevent(enum agsevent_type type, int code) { .mousey = mousey }; nact->ags.eventcb(&agse); // Async in emscripten + +#ifdef __EMSCRIPTEN__ + // HACK: this ensures that callers of this function are instrumented. + // This is necessary because ASYNCIFY_PROPAGATE_ADD does not work: + // https://github.com/emscripten-core/emscripten/issues/23015 + emscripten_sleep(0); +#endif } void sdl_setCursorInternalLocation(int x, int y) {