Skip to content

Commit 2c07fa6

Browse files
authored
[GLFW] Add missing checks before GLFW callbacks (#19148)
Also convert them all to if (..) { .. } notation (diff without whitespace is smaller). A few were left in the old format if the code benefited from that due to other reasons in the surrounding logic. Fixes #19145
1 parent df3a308 commit 2c07fa6

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

src/library_glfw.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ var LibraryGLFW = {
370370
#if USE_GLFW == 2
371371
{{{ makeDynCall('vii', 'GLFW.active.charFunc') }}}(charCode, 1);
372372
#endif
373-
374373
#if USE_GLFW == 3
375374
{{{ makeDynCall('vii', 'GLFW.active.charFunc') }}}(GLFW.active.id, charCode);
376375
#endif
@@ -387,16 +386,16 @@ var LibraryGLFW = {
387386
#endif
388387
GLFW.active.keys[key] = status;
389388
GLFW.active.domKeys[keyCode] = status;
390-
if (!GLFW.active.keyFunc) return;
391389

390+
if (GLFW.active.keyFunc) {
392391
#if USE_GLFW == 2
393-
{{{ makeDynCall('vii', 'GLFW.active.keyFunc') }}}(key, status);
392+
{{{ makeDynCall('vii', 'GLFW.active.keyFunc') }}}(key, status);
394393
#endif
395-
396394
#if USE_GLFW == 3
397-
if (repeat) status = 2; // GLFW_REPEAT
398-
{{{ makeDynCall('viiiii', 'GLFW.active.keyFunc') }}}(GLFW.active.id, key, keyCode, status, GLFW.getModBits(GLFW.active));
395+
if (repeat) status = 2; // GLFW_REPEAT
396+
{{{ makeDynCall('viiiii', 'GLFW.active.keyFunc') }}}(GLFW.active.id, key, keyCode, status, GLFW.getModBits(GLFW.active));
399397
#endif
398+
}
400399
},
401400

402401
onGamepadConnected: function(event) {
@@ -439,13 +438,14 @@ var LibraryGLFW = {
439438

440439
if (event.target != Module["canvas"] || !GLFW.active.cursorPosFunc) return;
441440

441+
if (GLFW.active.cursorPosFunc) {
442442
#if USE_GLFW == 2
443-
{{{ makeDynCall('vii', 'GLFW.active.cursorPosFunc') }}}(Browser.mouseX, Browser.mouseY);
443+
{{{ makeDynCall('vii', 'GLFW.active.cursorPosFunc') }}}(Browser.mouseX, Browser.mouseY);
444444
#endif
445-
446445
#if USE_GLFW == 3
447-
{{{ makeDynCall('vidd', 'GLFW.active.cursorPosFunc') }}}(GLFW.active.id, Browser.mouseX, Browser.mouseY);
446+
{{{ makeDynCall('vidd', 'GLFW.active.cursorPosFunc') }}}(GLFW.active.id, Browser.mouseX, Browser.mouseY);
448447
#endif
448+
}
449449
},
450450

451451
DOMToGLFWMouseButton: function(event) {
@@ -465,20 +465,24 @@ var LibraryGLFW = {
465465
onMouseenter: function(event) {
466466
if (!GLFW.active) return;
467467

468-
if (event.target != Module["canvas"] || !GLFW.active.cursorEnterFunc) return;
468+
if (event.target != Module["canvas"]) return;
469469

470470
#if USE_GLFW == 3
471-
{{{ makeDynCall('vii', 'GLFW.active.cursorEnterFunc') }}}(GLFW.active.id, 1);
471+
if (GLFW.active.cursorEnterFunc) {
472+
{{{ makeDynCall('vii', 'GLFW.active.cursorEnterFunc') }}}(GLFW.active.id, 1);
473+
}
472474
#endif
473475
},
474476

475477
onMouseleave: function(event) {
476478
if (!GLFW.active) return;
477479

478-
if (event.target != Module["canvas"] || !GLFW.active.cursorEnterFunc) return;
480+
if (event.target != Module["canvas"]) return;
479481

480482
#if USE_GLFW == 3
481-
{{{ makeDynCall('vii', 'GLFW.active.cursorEnterFunc') }}}(GLFW.active.id, 0);
483+
if (GLFW.active.cursorEnterFunc) {
484+
{{{ makeDynCall('vii', 'GLFW.active.cursorEnterFunc') }}}(GLFW.active.id, 0);
485+
}
482486
#endif
483487
},
484488

@@ -500,15 +504,14 @@ var LibraryGLFW = {
500504
GLFW.active.buttons &= ~(1 << eventButton);
501505
}
502506

503-
if (!GLFW.active.mouseButtonFunc) return;
504-
507+
if (GLFW.active.mouseButtonFunc) {
505508
#if USE_GLFW == 2
506-
{{{ makeDynCall('vii', 'GLFW.active.mouseButtonFunc') }}}(eventButton, status);
509+
{{{ makeDynCall('vii', 'GLFW.active.mouseButtonFunc') }}}(eventButton, status);
507510
#endif
508-
509511
#if USE_GLFW == 3
510-
{{{ makeDynCall('viiii', 'GLFW.active.mouseButtonFunc') }}}(GLFW.active.id, eventButton, status, GLFW.getModBits(GLFW.active));
512+
{{{ makeDynCall('viiii', 'GLFW.active.mouseButtonFunc') }}}(GLFW.active.id, eventButton, status, GLFW.getModBits(GLFW.active));
511513
#endif
514+
}
512515
},
513516

514517
onMouseButtonDown: function(event) {
@@ -528,11 +531,9 @@ var LibraryGLFW = {
528531
GLFW.wheelPos += delta;
529532

530533
if (!GLFW.active || !GLFW.active.scrollFunc || event.target != Module['canvas']) return;
531-
532534
#if USE_GLFW == 2
533535
{{{ makeDynCall('vi', 'GLFW.active.scrollFunc') }}}(GLFW.wheelPos);
534536
#endif
535-
536537
#if USE_GLFW == 3
537538
var sx = 0;
538539
var sy = delta;
@@ -594,24 +595,23 @@ var LibraryGLFW = {
594595
onWindowSizeChanged: function() {
595596
if (!GLFW.active) return;
596597

597-
if (!GLFW.active.windowSizeFunc) return;
598-
598+
if (GLFW.active.windowSizeFunc) {
599599
#if USE_GLFW == 2
600-
{{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height);
600+
{{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height);
601601
#endif
602-
603602
#if USE_GLFW == 3
604-
{{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
603+
{{{ makeDynCall('viii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
605604
#endif
605+
}
606606
},
607607

608608
onFramebufferSizeChanged: function() {
609609
if (!GLFW.active) return;
610610

611-
if (!GLFW.active.framebufferSizeFunc) return;
612-
613611
#if USE_GLFW == 3
614-
{{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
612+
if (GLFW.active.framebufferSizeFunc) {
613+
{{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height);
614+
}
615615
#endif
616616
},
617617

@@ -620,7 +620,9 @@ var LibraryGLFW = {
620620
if (!GLFW.active) return;
621621

622622
#if USE_GLFW == 3
623-
{{{ makeDynCall('viff', 'GLFW.active.windowContentScaleFunc') }}}(GLFW.active.id, GLFW.scale, GLFW.scale);
623+
if (GLFW.active.windowContentScaleFunc) {
624+
{{{ makeDynCall('viff', 'GLFW.active.windowContentScaleFunc') }}}(GLFW.active.id, GLFW.scale, GLFW.scale);
625+
}
624626
#endif
625627
},
626628

@@ -988,15 +990,14 @@ var LibraryGLFW = {
988990
}
989991
}
990992

991-
if (!win.windowSizeFunc) return;
992-
993+
if (win.windowSizeFunc) {
993994
#if USE_GLFW == 2
994-
{{{ makeDynCall('vii', 'win.windowSizeFunc') }}}(width, height);
995+
{{{ makeDynCall('vii', 'win.windowSizeFunc') }}}(width, height);
995996
#endif
996-
997997
#if USE_GLFW == 3
998-
{{{ makeDynCall('viii', 'win.windowSizeFunc') }}}(win.id, width, height);
998+
{{{ makeDynCall('viii', 'win.windowSizeFunc') }}}(win.id, width, height);
999999
#endif
1000+
}
10001001
},
10011002

10021003
createWindow: function(width, height, title, monitor, share) {
@@ -1063,8 +1064,9 @@ var LibraryGLFW = {
10631064
if (!win) return;
10641065

10651066
#if USE_GLFW == 3
1066-
if (win.windowCloseFunc)
1067+
if (win.windowCloseFunc) {
10671068
{{{ makeDynCall('vi', 'win.windowCloseFunc') }}}(win.id);
1069+
}
10681070
#endif
10691071

10701072
GLFW.windows[win.id - 1] = null;

0 commit comments

Comments
 (0)