Skip to content

Commit c0edf5b

Browse files
authored
[GLUT/GLFW] Stop resizing canvas to 1x1 on exit/termination (#27833)
In 2012, `Module["canvas"].width = Module["canvas"].height = 1` was added to the GLUT exit handler in `libglut.js` (#357) to simulate closing the window when a GLUT program calls `exit()`. When `libglfw.js` was created in 2013 (#1006), it was copied from `libglut.js` as a template along with the `atexit` handler in `glfwInit`, which was later moved into `glfwTerminate` when GLFW 3 support was added in 2014 (#1887). Remove this 1x1 canvas resize from both libraries: - Neither SDL1, SDL2, nor EGL resizes the canvas to 1x1 on shutdown or exit. - Calling `glfwInit()` followed by `glfwTerminate()` (even without creating a window) unexpectedly clobbers the canvas dimensions. - Resizing the canvas clears its bitmap, which destroys rendered output if an application renders a static frame and then calls `glfwTerminate()` or exits with `EXIT_RUNTIME=1`. - In GLFW HiDPI mode, inline CSS dimensions remain set on the canvas, so setting `width` and `height` to 1 only shrinks the backing buffer while leaving the element at its previous CSS size.
1 parent e81f854 commit c0edf5b

3 files changed

Lines changed: 2 additions & 6 deletions

File tree

‎src/lib/libglfw.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,6 @@ var LibraryGLFW = {
15011501
if (GLFW.devicePixelRatioMQL)
15021502
GLFW.devicePixelRatioMQL.removeEventListener('change', GLFW.onDevicePixelRatioChange);
15031503

1504-
canvas.width = canvas.height = 1;
15051504
GLFW.windows = null;
15061505
GLFW.active = null;
15071506
},

‎src/lib/libglut.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,6 @@ var LibraryGLUT = {
370370
window.removeEventListener('DOMMouseScroll', GLUT.onMouseWheel, true);
371371

372372
window.removeEventListener('resize', GLUT.onResize, true);
373-
374-
var canvas = Browser.getCanvas();
375-
canvas.width = canvas.height = 1;
376373
});
377374
},
378375

‎test/codesize/test_codesize_hello_dylink_all.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 271910,
2+
"a.out.js": 271876,
33
"a.out.nodebug.wasm": 587923,
4-
"total": 859833,
4+
"total": 859799,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)