Emscripten: Q: Should library_browser.js also check for the 'unwind' exception?

Created on 20 Jul 2020  路  3Comments  路  Source: emscripten-core/emscripten

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

good first bug help wanted

All 3 comments

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 ])

Was this page helpful?
0 / 5 - 0 ratings

Related issues

void4 picture void4  路  3Comments

lormuc picture lormuc  路  4Comments

napalm272 picture napalm272  路  4Comments

rpellerin picture rpellerin  路  3Comments

HolgerStrauss picture HolgerStrauss  路  4Comments