[eventloop] Fix main loop keepalive cleanup when cancelling or pausing - #27468
Merged
Merged
Conversation
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
3 times, most recently
from
July 31, 2026 19:59
139020e to
c02b9c2
Compare
kripken
reviewed
Aug 3, 2026
kripken
reviewed
Aug 4, 2026
| #if ASSERTIONS | ||
| assert(!MainLoop.func, 'emscripten_set_main_loop: there can only be one main loop function at once') | ||
| #endif | ||
| MainLoop.pause(); |
Member
There was a problem hiding this comment.
Why does "set main loop" pause the main loop? Especially since there is no current func to pause?
Collaborator
Author
There was a problem hiding this comment.
Good point, I just noticed this is redundant myself. The above assertion ensures this should never be needed.
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
2 times, most recently
from
August 5, 2026 06:05
2afb68e to
c0a37e2
Compare
kripken
reviewed
Aug 5, 2026
kripken
approved these changes
Aug 5, 2026
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
from
August 5, 2026 15:59
c0a37e2 to
02ff65c
Compare
sbc100
enabled auto-merge (squash)
August 5, 2026 15:59
Pop runtimeKeepaliveCounter immediately in MainLoop.pause() when a main loop is paused or cancelled, rather than deferring the pop until checkIsRunning() runs at the end of the next frame tick. This fixes cases where exit() or emscripten_force_exit() is called immediately after emscripten_cancel_main_loop() from within the main loop callback. Additionally, remove the redundant MainLoop.running property, using MainLoop.scheduler directly to determine if a main loop is active. Fixes: emscripten-core#27456
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
from
August 5, 2026 17:55
02ff65c to
5c31998
Compare
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.
Pop
runtimeKeepaliveCounterimmediately inMainLoop.pause()when a main loop is paused or cancelled, rather than deferring the pop untilcheckIsRunning()runs at the end of the next frame tick.This fixes cases where
exit()oremscripten_force_exit()is called immediately afteremscripten_cancel_main_loop()from within the main loop callback.Additionally, remove the redundant
MainLoop.runningproperty, using MainLoop.scheduler directly to determine if a main loop is active.Fixes: #27456