diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-04-04 17:07:41 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2012-04-04 17:07:41 -0400 |
commit | 109f8aa1e4b6247bb7dd2bd6559283ee4c6eb909 (patch) | |
tree | 348c09c02f31c0d1366bd6311911c5e7938160b6 /src/library_glut.js | |
parent | c01ef5762aa22c197018b2848c3a5dbe21ca3e20 (diff) |
Shut GLUT down upon exit()
Diffstat (limited to 'src/library_glut.js')
-rw-r--r-- | src/library_glut.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/library_glut.js b/src/library_glut.js index ba855187..30d27d17 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -186,11 +186,6 @@ var LibraryGLUT = { glutInit: function(argcp, argv) { // Ignore arguments GLUT.initTime = Date.now(); - window.addEventListener("keydown", GLUT.onKeydown, true); - window.addEventListener("keyup", GLUT.onKeyup, true); - window.addEventListener("mousemove", GLUT.onMousemove, true); - window.addEventListener("mousedown", GLUT.onMouseButtonDown, true); - window.addEventListener("mouseup", GLUT.onMouseButtonUp, true); }, glutInitWindowSize: function(width, height) { @@ -332,8 +327,23 @@ var LibraryGLUT = { } }, - glutMainLoop__deps: ['$GLUT', 'glutPostRedisplay'], + glutMainLoop__deps: ['$GLUT', 'atexit', 'glutPostRedisplay'], glutMainLoop: function() { + + window.addEventListener("keydown", GLUT.onKeydown, true); + window.addEventListener("keyup", GLUT.onKeyup, true); + window.addEventListener("mousemove", GLUT.onMousemove, true); + window.addEventListener("mousedown", GLUT.onMouseButtonDown, true); + window.addEventListener("mouseup", GLUT.onMouseButtonUp, true); + + _atexit(function() { + window.removeEventListener("keydown", GLUT.onKeydown, true); + window.removeEventListener("keyup", GLUT.onKeyup, true); + window.removeEventListener("mousemove", GLUT.onMousemove, true); + window.removeEventListener("mousedown", GLUT.onMouseButtonDown, true); + window.removeEventListener("mouseup", GLUT.onMouseButtonUp, true); + }); + if (GLUT.reshapeFunc) { FUNCTION_TABLE[GLUT.reshapeFunc](Module['canvas'].width, Module['canvas'].height); |