diff options
-rw-r--r-- | src/postamble.js | 5 | ||||
-rw-r--r-- | tests/doublestart.c | 23 | ||||
-rw-r--r-- | tests/test_browser.py | 13 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/postamble.js b/src/postamble.js index d6c059b8..90a86474 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -121,12 +121,13 @@ function run(args) { if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame function doRun() { + if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening + Module['calledRun'] = true; + ensureInitRuntime(); preMain(); - assert(!Module['calledRun']); - Module['calledRun'] = true; if (Module['_main'] && shouldRunNow) { Module['callMain'](args); } diff --git a/tests/doublestart.c b/tests/doublestart.c new file mode 100644 index 00000000..533e6308 --- /dev/null +++ b/tests/doublestart.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <emscripten.h> + +int times = 0; + +void later(void* nada) { + int result = times; + REPORT_RESULT(); +} + +void main_loop(void) { + static int cnt = 0; + if (++cnt >= 10) emscripten_cancel_main_loop(); +} + +int main(void) { + emscripten_async_call(later, NULL, 2000); + times++; + printf("This should only appear once.\n"); + emscripten_set_main_loop(main_loop, 10, 0); + return 0; +} + diff --git a/tests/test_browser.py b/tests/test_browser.py index 23022604..eed18a3d 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1751,3 +1751,16 @@ keydown(100);keyup(100); // trigger the end self.btest(path_from_root('tests', 'glew.c'), args=['-s', 'LEGACY_GL_EMULATION=1'], expected='1') self.btest(path_from_root('tests', 'glew.c'), args=['-DGLEW_MX'], expected='1') self.btest(path_from_root('tests', 'glew.c'), args=['-s', 'LEGACY_GL_EMULATION=1', '-DGLEW_MX'], expected='1') + + def test_doublestart_bug(self): + open('pre.js', 'w').write(r''' +if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()'); +if (!Module['preRun']) Module['preRun'] = []; +Module["preRun"].push(function () { + Module['addRunDependency']('test_run_dependency'); + Module['removeRunDependency']('test_run_dependency'); +}); +''') + + self.btest('doublestart.c', args=['--pre-js', 'pre.js', '-o', 'test.html'], expected='1') + |