Skip to content

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

Merged
merged 2 commits into from
May 5, 2022

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented May 3, 2022

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.

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.
@sbc100
Copy link
Collaborator

sbc100 commented May 3, 2022

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 main) can still work fine?

@@ -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.
Copy link
Collaborator

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"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@aheejin
Copy link
Member Author

aheejin commented May 3, 2022

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 main) can still work fine?

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 emscripten_set_main_loop?

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

Successfully merging this pull request may close these issues.

3 participants