Skip to content

Commit df1ba7e

Browse files
authored
Add assertion SDL_SetVideoMode. NFC (emscripten-core#24177)
Also, avoid calling Browser.getCanvas() repeatedly withing this function.
1 parent 66619bc commit df1ba7e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/libsdl.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,15 +1484,19 @@ var LibrarySDL = {
14841484
SDL_SetVideoMode__deps: ['$GL'],
14851485
SDL_SetVideoMode__proxy: 'sync',
14861486
SDL_SetVideoMode: (width, height, depth, flags) => {
1487+
var canvas = Browser.getCanvas();
1488+
#if ASSERTIONS
1489+
assert(canvas, 'no canvas found');
1490+
#endif
1491+
14871492
['touchstart', 'touchend', 'touchmove',
14881493
'mousedown', 'mouseup', 'mousemove',
14891494
'mousewheel', 'wheel', 'mouseout',
14901495
'DOMMouseScroll',
1491-
].forEach((e) => Browser.getCanvas().addEventListener(e, SDL.receiveEvent, true));
1496+
].forEach((e) => canvas.addEventListener(e, SDL.receiveEvent, true));
14921497

14931498
// (0,0) means 'use fullscreen' in native; in Emscripten, use the current canvas size.
14941499
if (width == 0 && height == 0) {
1495-
var canvas = Browser.getCanvas();
14961500
width = canvas.width;
14971501
height = canvas.height;
14981502
}

0 commit comments

Comments
 (0)