-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add note on emscripten_set_main_loop with Wasm EH #16871
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
Conversation
When `simulate_infinite_loop` is true, `emscripten_set_main_loop` does not work with the new Wasm EH because throwing a JS exception will cause destructors in the Wasm stack frames to run. This can be fixed in future by either by fixing the LLVM compilation by adding an additional `catch` to every `catch_all` so that we can rethrow JS exceptions of this kind, or possibly using the new stack switching proposal. This PR adds a note that this features currently doesn't work with Wasm EH.
This is rather unfortunate... given that it doesn't work can we assert at runtime if this flag is passed? Or at least write a warning the console? I guess it only really matters if you have C++ object in your stack when you call it so many users (e.g SDL games who call this from |
@@ -361,6 +361,8 @@ Functions | |||
|
|||
.. note:: Calling this function overrides the effect of any previous calls to :c:func:`emscripten_set_main_loop_timing` in the calling thread by applying the timing mode specified by the parameter ``fps``. To specify a different timing mode for the current thread, call the function :c:func:`emscripten_set_main_loop_timing` after setting up the main loop. | |||
|
|||
.. note:: Currently, ``simulate_infinite_loop`` == true does not work yet with `the new Wasm exception handling <https://emscripten.org/docs/porting/exceptions.html#webassembly-exception-handling-proposal>`_; your program may crash with memory errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps mention "does not work in C++ projects that have objects with destructors on the stack at the time of the call"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I think you're right; if you don't have any destructors to run this will work fine. So if you only call this from the main without any stack-allocated objects this should be fine. So I'm not sure if we should assert... maybe a warning is enough? (Then where should we warn? Inside |
When
simulate_infinite_loop
is true,emscripten_set_main_loop
doesnot work with the new Wasm EH
because throwing a JS exception will cause destructors in the Wasm stack
frames to run. This can be fixed in future by either by fixing the LLVM
compilation by adding an additional
catch
to everycatch_all
so thatwe can rethrow JS exceptions of this kind, or possibly using the new
stack switching proposal.
This PR adds a note that this features currently doesn't work with Wasm
EH.