How to properly handle application life (and exit)

567 views
Skip to first unread message

Robert Goulet

unread,
May 10, 2016, 11:12:40 AM5/10/16
to emscripten-discuss
Hi all,

what is the proper way to handle application exit? For instance, what's the proper code when your main is setup as such (simulated infinite loop) :

void update(void* args)
{
    App* app = (App*)args;
    app->update();
}

int main()
{
    init_systems();
    auto app = new App;
    emscripten_set_main_loop_arg(&update, app, 0, true);
    delete app;
    free_systems();
}

How do we exit the emscripten main loop and continue executing whatever code that exist beyond the main loop?

On a similar topic, upon assertions/errors in code, how do we completely stop the application/javascript with a behavior similar to C exit(code) function? When we call exit(code), it seems main loop is still running?

What's the general guideline for application life cycle?

Thanks!

Alon Zakai

unread,
May 10, 2016, 1:01:35 PM5/10/16
to emscripten-discuss
The code after the simulated infinite loop can't execute. Instead, you can put it in a method and call it after calling cancel_main_loop.

Errors should cancel the main loop, as well as all other async callbacks - we set the global JS var ABORT when everything should exit. exit() will do the same, unless noExitRuntime is set, which async callbacks like the main loop invoke. Instead of normal exit(), you can call emscripten_force_exit() which make sure no more code runs after it.

--
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.
For more options, visit https://groups.google.com/d/optout.

Robert Goulet

unread,
May 17, 2016, 1:54:15 PM5/17/16
to emscripten-discuss
Great that worked well.

Is there a way to do equivalent of emscripten_force_exit or emscripten_cancel_main_loop from javascript side? For example, we'd like to have a browser version test and stop further execution if we know the browser won't be supported.

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Alon Zakai

unread,
May 17, 2016, 2:07:13 PM5/17/16
to emscripten-discuss
Yes, if you export one of those methods, you can call them on Module using Module._emscripten_...() etc. (note _ prefix).

To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.
Reply all
Reply to author
Forward
0 new messages