From f25f2fa17a59182b34e5f68f725ef14b7c7f38a6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 2 May 2014 11:05:04 -0700 Subject: document and assert on only one browser main loop at a time --- src/library_browser.js | 2 ++ system/include/emscripten/emscripten.h | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/library_browser.js b/src/library_browser.js index 5cc7e122..44e8c473 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -889,6 +889,8 @@ mergeInto(LibraryManager.library, { emscripten_set_main_loop: function(func, fps, simulateInfiniteLoop, arg) { Module['noExitRuntime'] = true; + assert(!Browser.mainLoop.scheduler, 'there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one, if you want to'); + Browser.mainLoop.runner = function Browser_mainLoop_runner() { if (ABORT) return; if (Browser.mainLoop.queue.length > 0) { diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index 73836018..362a1337 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -121,7 +121,11 @@ extern void emscripten_async_load_script(const char *script, void (*onload)(void * * If you want your main loop function to receive a void* * argument, use emscripten_set_main_loop_arg. - + * + * There can be only *one* main loop function at a time. You + * can cancel the current one and set another, if you want to + * change it. + * * @simulate_infinite_loop If true, this function will throw an * exception in order to stop execution of the caller. This * will lead to the main loop being entered instead of code -- cgit v1.2.3-18-g5258