From 473543736f8bb1e119af93f87451089089e8bd74 Mon Sep 17 00:00:00 2001 From: kamenokonokotan Date: Wed, 6 Jul 2022 18:25:48 +0900 Subject: [PATCH 1/5] supress runtime exit while calling callUserCallback --- src/library_glfw.js | 4 ++-- tests/glfw3.c | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/library_glfw.js b/src/library_glfw.js index b8325f502dd99..f5c957e452e2f 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -598,7 +598,7 @@ var LibraryGLFW = { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif - }); + }, true); }, onFramebufferSizeChanged: function() { @@ -610,7 +610,7 @@ var LibraryGLFW = { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif - }); + }, true); }, getTime: function() { diff --git a/tests/glfw3.c b/tests/glfw3.c index 41da337dc7425..e7eb6745880d4 100644 --- a/tests/glfw3.c +++ b/tests/glfw3.c @@ -41,6 +41,13 @@ assert(glfwSet##Function(Value) == Value); /* The previously set callback */ assert(glfwSet##Function(Window, Value) == NULL); /* Default value (no callback was set) */ \ assert(glfwSet##Function(Window, Value) == Value); /* The previously set callback */ +static int exited = 0; + +__attribute__((destructor)) +void onExit() { + exited = 1; +} + int main() { GLFWwindow *window; @@ -117,10 +124,12 @@ int main() glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); + assert(exited == 0); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); + assert(exited == 0); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); From 25e1a1996538efa0f22ea846b7ca9be7f48ccc89 Mon Sep 17 00:00:00 2001 From: nokotan Date: Thu, 7 Jul 2022 15:31:44 +0900 Subject: [PATCH 2/5] correct assert exited position --- tests/glfw3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/glfw3.c b/tests/glfw3.c index e7eb6745880d4..a2e0f8d6d456f 100644 --- a/tests/glfw3.c +++ b/tests/glfw3.c @@ -124,7 +124,6 @@ int main() glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); - assert(exited == 0); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); @@ -133,6 +132,7 @@ int main() glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); + assert(exited == 0); // XXX: not implemented // glfwIconifyWindow(window); From e85d0b4c1fa1bd5366ef0a33658dc7c4506727a8 Mon Sep 17 00:00:00 2001 From: nokotan Date: Thu, 7 Jul 2022 15:32:34 +0900 Subject: [PATCH 3/5] use runtimeKeepalivePush/runtimeKeepalivePop --- src/library_glfw.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/library_glfw.js b/src/library_glfw.js index f5c957e452e2f..fe16951ebaeba 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -590,6 +590,7 @@ var LibraryGLFW = { if (!GLFW.active.windowSizeFunc) return; + {{{ runtimeKeepalivePush() }}} callUserCallback(function() { #if USE_GLFW == 2 {{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height); @@ -598,7 +599,8 @@ var LibraryGLFW = { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif - }, true); + }); + {{{ runtimeKeepalivePop() }}} }, onFramebufferSizeChanged: function() { @@ -606,11 +608,13 @@ var LibraryGLFW = { if (!GLFW.active.framebufferSizeFunc) return; + {{{ runtimeKeepalivePush() }}} callUserCallback(function() { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif - }, true); + }); + {{{ runtimeKeepalivePop() }}} }, getTime: function() { From b768ee69c7c24aadcb4d89a523fc3ab971eb8afe Mon Sep 17 00:00:00 2001 From: nokotan Date: Sat, 9 Jul 2022 14:01:10 +0900 Subject: [PATCH 4/5] Add case exit_runtime with test_glfw3 --- tests/test_browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_browser.py b/tests/test_browser.py index 70b43e31ee389..aa40b86eb6cbe 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -2864,7 +2864,7 @@ def in_html(expected): 'gl_es': (['-DCLIENT_API=GLFW_OPENGL_ES_API'],) }) def test_glfw3(self, args): - for opts in [[], ['-sLEGACY_GL_EMULATION'], ['-Os', '--closure=1']]: + for opts in [[], ['-sEXIT_RUNTIME=1'], ['-sLEGACY_GL_EMULATION'], ['-Os', '--closure=1']]: print(opts) self.btest(test_file('glfw3.c'), args=['-sUSE_GLFW=3', '-lglfw', '-lGL'] + args + opts, expected='1') From 832023d76dd7a44ae7bf3ae468cc328933e97142 Mon Sep 17 00:00:00 2001 From: nokotan Date: Tue, 12 Jul 2022 13:49:48 +0900 Subject: [PATCH 5/5] move runtimeKeepalivePush/Pop to setWindowSize --- src/library_glfw.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/library_glfw.js b/src/library_glfw.js index fe16951ebaeba..ced031908132b 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -590,7 +590,6 @@ var LibraryGLFW = { if (!GLFW.active.windowSizeFunc) return; - {{{ runtimeKeepalivePush() }}} callUserCallback(function() { #if USE_GLFW == 2 {{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height); @@ -600,7 +599,6 @@ var LibraryGLFW = { {{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif }); - {{{ runtimeKeepalivePop() }}} }, onFramebufferSizeChanged: function() { @@ -608,13 +606,11 @@ var LibraryGLFW = { if (!GLFW.active.framebufferSizeFunc) return; - {{{ runtimeKeepalivePush() }}} callUserCallback(function() { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif }); - {{{ runtimeKeepalivePop() }}} }, getTime: function() { @@ -963,6 +959,7 @@ var LibraryGLFW = { if (!win) return; if (GLFW.active.id == win.id) { + {{{ runtimeKeepalivePush() }}} if (width == screen.width && height == screen.height) { Browser.requestFullscreen(); } else { @@ -971,6 +968,7 @@ var LibraryGLFW = { win.width = width; win.height = height; } + {{{ runtimeKeepalivePop() }}} } if (!win.windowSizeFunc) return;