Skip to content

Commit e17c7f2

Browse files
authored
Fix glfw usage of callUserCallback and add checks around it (#17441)
Supersedes #17438 and #17376.
1 parent 960b0ea commit e17c7f2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/library_glfw.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ var LibraryGLFW = {
8080
},
8181

8282
$GLFW__deps: ['emscripten_get_now', '$GL', '$Browser', '$GLFW_Window',
83-
'$callUserCallback',
8483
'$allocateUTF8',
8584
#if FILESYSTEM
8685
'$FS',
@@ -591,27 +590,23 @@ var LibraryGLFW = {
591590

592591
if (!GLFW.active.windowSizeFunc) return;
593592

594-
callUserCallback(function() {
595593
#if USE_GLFW == 2
596-
{{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height);
594+
{{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height);
597595
#endif
598596

599597
#if USE_GLFW == 3
600-
{{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
598+
{{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
601599
#endif
602-
});
603600
},
604601

605602
onFramebufferSizeChanged: function() {
606603
if (!GLFW.active) return;
607604

608605
if (!GLFW.active.framebufferSizeFunc) return;
609606

610-
callUserCallback(function() {
611607
#if USE_GLFW == 3
612-
{{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
608+
{{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
613609
#endif
614-
});
615610
},
616611

617612
getTime: function() {
@@ -1132,7 +1127,7 @@ var LibraryGLFW = {
11321127
Module["canvas"].addEventListener('drop', GLFW.onDrop, true);
11331128
Module["canvas"].addEventListener('dragover', GLFW.onDragover, true);
11341129

1135-
Browser.resizeListeners.push(function(width, height) {
1130+
Browser.resizeListeners.push((width, height) => {
11361131
GLFW.onCanvasResize(width, height);
11371132
});
11381133
return 1; // GL_TRUE

tests/browser/test_glfw3.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ assert(glfwSet##Function(Value) == Value); /* The previously set callback */
4141
assert(glfwSet##Function(Window, Value) == NULL); /* Default value (no callback was set) */ \
4242
assert(glfwSet##Function(Window, Value) == Value); /* The previously set callback */
4343

44+
static int exited = 0;
45+
46+
__attribute__((destructor))
47+
void onExit() {
48+
exited = 1;
49+
}
50+
4451
int main()
4552
{
4653
GLFWwindow *window;
@@ -121,9 +128,11 @@ int main()
121128
glfwSetWindowSize(window, 1, 1);
122129
glfwGetWindowSize(window, &w, &h);
123130
assert(w == 1 && h == 1);
131+
assert(exited == 0);
124132

125133
glfwSetWindowSize(window, 640, 480);
126134
glfwGetFramebufferSize(window, &w, &h);
135+
assert(exited == 0);
127136

128137
// XXX: not implemented
129138
// glfwIconifyWindow(window);

0 commit comments

Comments
 (0)