I'm wondering about a slight discrepancy, between the handler in postamble.js:callMainand library_browser.js:mainLoop:runIter:
runIter: function(func) {
if (ABORT) return;
if (Module['preMainLoop']) {
var preRet = Module['preMainLoop']();
if (preRet === false) {
return; // |return false| skips a frame
}
}
try {
func();
} catch (e) {
if (e instanceof ExitStatus) {
return;
// -> NO CHECK FOR "} else if (e == 'unwind') {" ?
} else {
if (e && typeof e === 'object' && e.stack) err('exception thrown: ' + [e, e.stack]);
throw e;
}
}
if (Module['postMainLoop']) Module['postMainLoop']();
}
My situation is that I'm trying to restart the app, via the step function set in emscripten_set_main_loop_arg(step_method, user_data, 0, 1);.
Within the step_method, I detect that I need to restart my app, and the way it's built, the "step_method" it just that, a step method, not a full exit/init function. But, now that I added that, I used this (from within a call to step_method):
void step_method(void* user_data) {
if (restart) {
emscripten_pause_main_loop(); // stop further callbacks
emscripten_cancel_main_loop(); // Causes an exception
emscripten_set_main_loop_arg(step_method, new_user_data, 0, 1);
}
... do step work
}
The code works, but I also get a pesky exception "unwind", which trigger the crash dump mechanism. Looking at the postamble.js code, there's a case which checks this case, and I wonder if that's simply missing from library_browser.js?
Regards
/Mathias
Yes, I think you're right, that should be handled as well. And we should add a test for restarting the main loop that way, alongside the other tests with main_loop in their name in tests/test_browser.py.
Ok, thanks for the info! I'd like to take a stab at making a PR for this then (hopefully this weekend).
I have now added a fix+test, but I need help getting the test to actually fail, since it seems to silently swallow the exception ([client logging: /?exception=uncaught exception: unwind / undefined ])