diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-05-22 14:33:04 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-05-22 14:33:04 -0700 |
commit | 77d94eb04fad6749788df00e992d97647ec0f61f (patch) | |
tree | 991f0b67c5f2c70f2ec8bc8ace5f5f36f89c8c38 /src/library_browser.js | |
parent | 0d4f492e4dc3d02484028e6428c55fab978c7a8b (diff) |
do not call code-running callbacks if ABORTing; fixes #1191
Diffstat (limited to 'src/library_browser.js')
-rw-r--r-- | src/library_browser.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 0ed04e19..121b222b 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -184,7 +184,7 @@ mergeInto(LibraryManager.library, { }; audio.src = url; // workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror - setTimeout(function() { + Browser.safeSetTimeout(function() { finish(audio); // try to use it even though it is not necessarily ready to play }, 10000); } else { @@ -361,6 +361,23 @@ mergeInto(LibraryManager.library, { window.requestAnimationFrame(func); }, + // abort-aware versions + safeRequestAnimationFrame: function(func) { + Browser.requestAnimationFrame(function() { + if (!ABORT) func(); + }); + }, + safeSetTimeout: function(func, timeout) { + setTimeout(function() { + if (!ABORT) func(); + }, timeout); + }, + safeSetInterval: function(func, timeout) { + setInterval(function() { + if (!ABORT) func(); + }, timeout); + }, + getMovementX: function(event) { return event['movementX'] || event['mozMovementX'] || @@ -612,7 +629,7 @@ mergeInto(LibraryManager.library, { Module['noExitRuntime'] = true; // TODO: cache these to avoid generating garbage - setTimeout(function() { + Browser.safeSetTimeout(function() { _emscripten_run_script(script); }, millis); }, @@ -621,6 +638,7 @@ mergeInto(LibraryManager.library, { Module['noExitRuntime'] = true; Browser.mainLoop.runner = function() { + if (ABORT) return; if (Browser.mainLoop.queue.length > 0) { var start = Date.now(); var blocker = Browser.mainLoop.queue.shift(); @@ -723,9 +741,9 @@ mergeInto(LibraryManager.library, { } if (millis >= 0) { - setTimeout(wrapper, millis); + Browser.safeSetTimeout(wrapper, millis); } else { - Browser.requestAnimationFrame(wrapper); + Browser.safeRequestAnimationFrame(wrapper); } }, |