Conversation
The g_wasm_ctx global (BSS-resident, initialized to NULL) was lost across Emscripten's main-loop unwind transition when emscripten_set_main_loop_arg() exits main() via throw "unwind" with -sASYNCIFY. This caused all exported input injection functions (iui_wasm_mouse_button, iui_wasm_mouse_motion, etc.) called from JavaScript event handlers to silently bail out, making mouse interaction non-functional. The ctx pointer passed through the port function table remains valid (heap-allocated via calloc), so re-establish g_wasm_ctx at the start of wasm_poll_events() each frame before JS event callbacks can reference it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The g_wasm_ctx global (BSS-resident, initialized to NULL) was lost across Emscripten's main-loop unwind transition when emscripten_set_main_loop_arg() exits main() via throw "unwind" with
-sASYNCIFY. This caused all exported input injection functions (iui_wasm_mouse_button,iui_wasm_mouse_motion, etc.) called from JavaScript event handlers to silently bail out, making mouse interaction non-functional.The ctx pointer passed through the port function table remains valid (heap-allocated via calloc), so re-establish
g_wasm_ctxat the start ofwasm_poll_events()each frame before JS event callbacks can reference it.Summary by cubic
Restore mouse input in WASM by re-establishing g_wasm_ctx at the start of each frame in wasm_poll_events. This fixes the lost global after Emscripten’s ASYNCIFY main-loop unwind, which caused JS-driven input functions to no-op.
Written for commit d89db97. Summary will update on new commits.