aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-22 14:33:04 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-22 14:33:04 -0700
commit77d94eb04fad6749788df00e992d97647ec0f61f (patch)
tree991f0b67c5f2c70f2ec8bc8ace5f5f36f89c8c38 /src
parent0d4f492e4dc3d02484028e6428c55fab978c7a8b (diff)
do not call code-running callbacks if ABORTing; fixes #1191
Diffstat (limited to 'src')
-rw-r--r--src/library_browser.js26
-rw-r--r--src/library_gc.js2
-rw-r--r--src/library_glut.js10
-rw-r--r--src/library_sdl.js2
-rw-r--r--src/postamble.js2
-rw-r--r--src/preamble.js2
6 files changed, 32 insertions, 12 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);
}
},
diff --git a/src/library_gc.js b/src/library_gc.js
index 2a164250..b3dae0e9 100644
--- a/src/library_gc.js
+++ b/src/library_gc.js
@@ -26,7 +26,7 @@ if (GC_SUPPORT) {
_GC_finalizer_notifier = _malloc(4); setValue(_GC_finalizer_notifier, 0, 'i32');
if (ENVIRONMENT_IS_WEB) {
- setInterval(function() {
+ Browser.safeSetInterval(function() {
GC.maybeCollect();
}, 1000);
} else {
diff --git a/src/library_glut.js b/src/library_glut.js
index 35348028..38cfe55b 100644
--- a/src/library_glut.js
+++ b/src/library_glut.js
@@ -322,16 +322,17 @@ var LibraryGLUT = {
var callback = function() {
if (GLUT.idleFunc) {
Runtime.dynCall('v', GLUT.idleFunc);
- window.setTimeout(callback, 0);
+ Browser.safeSetTimeout(callback, 0);
}
}
- if (!GLUT.idleFunc)
- window.setTimeout(callback, 0);
+ if (!GLUT.idleFunc) {
+ Browser.safeSetTimeout(callback, 0);
+ }
GLUT.idleFunc = func;
},
glutTimerFunc: function(msec, func, value) {
- window.setTimeout(function() { Runtime.dynCall('vi', func, [value]); }, msec);
+ Browser.safeSetTimeout(function() { Runtime.dynCall('vi', func, [value]); }, msec);
},
glutDisplayFunc: function(func) {
@@ -419,6 +420,7 @@ var LibraryGLUT = {
glutPostRedisplay: function() {
if (GLUT.displayFunc) {
Browser.requestAnimationFrame(function() {
+ if (ABORT) return;
Runtime.dynCall('v', GLUT.displayFunc);
});
}
diff --git a/src/library_sdl.js b/src/library_sdl.js
index a5080a99..d31c37f5 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1197,7 +1197,7 @@ var LibrarySDL = {
SDL_PauseAudio: function(pauseOn) {
if (SDL.audio.paused !== pauseOn) {
- SDL.audio.timer = pauseOn ? SDL.audio.timer && clearInterval(SDL.audio.timer) : setInterval(SDL.audio.caller, 1/35);
+ SDL.audio.timer = pauseOn ? SDL.audio.timer && clearInterval(SDL.audio.timer) : Browser.safeSetInterval(SDL.audio.caller, 1/35);
}
SDL.audio.paused = pauseOn;
},
diff --git a/src/postamble.js b/src/postamble.js
index d0b737f8..49fd9b3e 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -104,7 +104,7 @@ function run(args) {
setTimeout(function() {
Module['setStatus']('');
}, 1);
- doRun();
+ if (!ABORT) doRun();
}, 1);
return 0;
} else {
diff --git a/src/preamble.js b/src/preamble.js
index 659b3869..35dfeba9 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -231,7 +231,7 @@ var setjmpId = 1; // Used in setjmp/longjmp
var setjmpLabels = {};
#endif
-var ABORT = false;
+var ABORT = false; // whether we are quitting the application. no code should run after this. set in exit() and abort()
var undef = 0;
// tempInt is used for 32-bit signed values or smaller. tempBigInt is used