Skip to content

Commit f6f23dd

Browse files
committed
Fix glfw usage of callUserCallback and add checks around it
Supersedes #17438 and #17376.
1 parent 584a0bf commit f6f23dd

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/library.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,10 @@ mergeInto(LibraryManager.library, {
35003500
return;
35013501
}
35023502
try {
3503+
#if ASSERTIONS
3504+
assert(!inUserCode, 'callUserCallback called when already running user code');
3505+
inUserCode = true;
3506+
#endif
35033507
func();
35043508
#if EXIT_RUNTIME || USE_PTHREADS
35053509
#if USE_PTHREADS && !EXIT_RUNTIME
@@ -3510,6 +3514,9 @@ mergeInto(LibraryManager.library, {
35103514
} catch (e) {
35113515
handleException(e);
35123516
}
3517+
#if ASSERTIONS
3518+
inUserCode = false;
3519+
#endif
35133520
},
35143521

35153522
$maybeExit__deps: ['exit', '$handleException',

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

src/postamble.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ function callMain(args) {
161161
abortWrapperDepth += 2;
162162
#endif
163163

164+
#if ASSERTIONS
165+
inUserCode = true;
166+
#endif
164167
#if STANDALONE_WASM
165168
entryFunction();
166169
// _start (in crt1.c) will call exit() if main return non-zero. So we know
@@ -189,6 +192,9 @@ function callMain(args) {
189192
return handleException(e);
190193
#endif // !PROXY_TO_PTHREAD
191194
} finally {
195+
#if ASSERTIONS
196+
inUserCode = false;
197+
#endif
192198
calledMain = true;
193199

194200
#if ABORT_ON_WASM_EXCEPTIONS

src/preamble.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ var runDependencyWatcher = null;
368368
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
369369
#if ASSERTIONS
370370
var runDependencyTracking = {};
371+
var inUserCode = false;
371372
#endif
372373

373374
function getUniqueRunDependency(id) {

0 commit comments

Comments
 (0)