noExitRuntime and shutting down emscripten runtime

254 views
Skip to first unread message

Christopher Dyken

unread,
Mar 22, 2021, 1:47:24 PM3/22/21
to emscripten-discuss
Hi,

I use emscripten for a project where I set noExitRuntime=1 since I want to manage the main loop myself in javascript-land. And that works well.

However, I also need to shut down and clean up the module, but I haven't managed to find a way to invoke the shutdown code?

I'm considering trying to do the init code in a dedicated function using noInitialRun=1 and call main() for shutdown. But maybe I am missing something?

Thanks,

Christopher

Sam Clegg

unread,
Mar 22, 2021, 4:42:08 PM3/22/21
to emscripte...@googlegroups.com
You should be able to set `noExitRuntime = 0` and then call `exit(0)` (or `Module.exit(0)`).   

cheers,
sam

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/a3a32735-9904-4a21-bf0b-fa118c3569a3n%40googlegroups.com.

Christopher Dyken

unread,
Mar 23, 2021, 5:51:43 AM3/23/21
to emscripten-discuss
Thanks for your reply!

But if I clear `noExitRuntime`, then exiting `main()` will shut down the runtime as well?

I tried at init:
- set`noExitRuntime=0` and `noInitialRun=1`
- move the body of my `main()` into an init function and let `main()` have an empty body
- invoke my init function at end of `postRun`

Then the main-loop runs in javascript.

And then when shutting down:
- run `callMain()`

This appears to work as I want, application seems to get events and rendering works, and event handlers seem to be cleaned up when shutting down.

Thanks,
Christopher

Sam Clegg

unread,
Mar 23, 2021, 1:27:01 PM3/23/21
to emscripte...@googlegroups.com
On Tue, Mar 23, 2021 at 2:51 AM Christopher Dyken <christop...@gmail.com> wrote:
Thanks for your reply!

But if I clear `noExitRuntime`, then exiting `main()` will shut down the runtime as well?

I meant set `noExitRuntime=1` at startup, and then when you want to exit you can set it to `0` before calling `exit()`.

Actually we have a special function that does basically this: `emscripten_force_exit()`



Christopher Dyken

unread,
Mar 23, 2021, 2:36:57 PM3/23/21
to emscripten-discuss
Thanks, that looks like precisely what I was looking for!
Reply all
Reply to author
Forward
0 new messages