Skip to content

Commit

Permalink
[Wasm64] Fix empty glfw3 functions. NFC (#23448)
Browse files Browse the repository at this point in the history
For functions that return a pointer we need cannot return undefined
otherwise we get `Cannot convert undefined to a BigInt`.

Fixes: #23446
  • Loading branch information
sbc100 authored Jan 17, 2025
1 parent 1b0797c commit 677accc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,9 @@ var LibraryGLFW = {
#endif
},

glfwPollEvents: () => {},
glfwPollEvents: () => 0,

glfwWaitEvents: () => {},
glfwWaitEvents: () => 0,

glfwGetTime: () => GLFW.getTime() - GLFW.initialTime,

Expand Down Expand Up @@ -1509,9 +1509,9 @@ var LibraryGLFW = {
return prevcbfun;
},

glfwWaitEventsTimeout: (timeout) => {},
glfwWaitEventsTimeout: (timeout) => 0,

glfwPostEmptyEvent: () => {},
glfwPostEmptyEvent: () => 0,

glfwGetMonitors__deps: ['malloc'],
glfwGetMonitors: (count) => {
Expand Down Expand Up @@ -1573,7 +1573,7 @@ var LibraryGLFW = {
glfwGetVideoMode: (monitor) => 0,

// TODO: implement
glfwSetGamma: (monitor, gamma) => {},
glfwSetGamma: (monitor, gamma) => 0,

glfwGetGammaRamp: (monitor) => { throw "glfwGetGammaRamp not implemented."; },

Expand Down Expand Up @@ -1659,9 +1659,9 @@ var LibraryGLFW = {
#endif
},

glfwShowWindow: (winid) => {},
glfwShowWindow: (winid) => 0,

glfwHideWindow: (winid) => {},
glfwHideWindow: (winid) => 0,

glfwGetWindowMonitor: (winid) => {
var win = GLFW.WindowFromId(winid);
Expand Down Expand Up @@ -1727,29 +1727,29 @@ var LibraryGLFW = {
return prevcbfun;
},

glfwSetWindowIcon: (winid, count, images) => {},
glfwSetWindowIcon: (winid, count, images) => 0,

glfwSetWindowSizeLimits: (winid, minwidth, minheight, maxwidth, maxheight) => {},
glfwSetWindowSizeLimits: (winid, minwidth, minheight, maxwidth, maxheight) => 0,

glfwSetWindowAspectRatio: (winid, numer, denom) => {},
glfwSetWindowAspectRatio: (winid, numer, denom) => 0,

glfwGetWindowFrameSize: (winid, left, top, right, bottom) => { throw "glfwGetWindowFrameSize not implemented."; },

glfwMaximizeWindow: (winid) => {},
glfwMaximizeWindow: (winid) => 0,

glfwFocusWindow: (winid) => {},
glfwFocusWindow: (winid) => 0,

glfwRequestWindowAttention: (winid) => {}, // maybe do window.focus()?
glfwRequestWindowAttention: (winid) => 0, // maybe do window.focus()?

glfwSetWindowMonitor: (winid, monitor, xpos, ypos, width, height, refreshRate) => { throw "glfwSetWindowMonitor not implemented."; },

glfwCreateCursor: (image, xhot, yhot) => {},
glfwCreateCursor: (image, xhot, yhot) => 0,

glfwCreateStandardCursor: (shape) => {},
glfwCreateStandardCursor: (shape) => 0,

glfwDestroyCursor: (cursor) => {},
glfwDestroyCursor: (cursor) => 0,

glfwSetCursor: (winid, cursor) => {},
glfwSetCursor: (winid, cursor) => 0,

glfwSetFramebufferSizeCallback: (winid, cbfun) => {
var win = GLFW.WindowFromId(winid);
Expand Down Expand Up @@ -1884,11 +1884,11 @@ var LibraryGLFW = {

glfwSetJoystickCallback: (cbfun) => GLFW.setJoystickCallback(cbfun),

glfwSetClipboardString: (win, string) => {},
glfwSetClipboardString: (win, string) => 0,

glfwGetClipboardString: (win) => {},
glfwGetClipboardString: (win) => 0,

glfwMakeContextCurrent: (winid) => {},
glfwMakeContextCurrent: (winid) => 0,

glfwGetCurrentContext: () => GLFW.active ? GLFW.active.id : 0,

Expand Down Expand Up @@ -1964,7 +1964,7 @@ var LibraryGLFW = {

glfwGetMouseWheel: () => 0,

glfwSetMouseWheel: (pos) => {},
glfwSetMouseWheel: (pos) => 0,

glfwSetKeyCallback_v2: (cbfun) => {
GLFW.setKeyCallback(GLFW.active.id, cbfun);
Expand Down Expand Up @@ -2013,9 +2013,9 @@ var LibraryGLFW = {
return 0;
},

glfwDestroyThread: (ID) => {},
glfwDestroyThread: (ID) => 0,

glfwWaitThread: (ID, waitmode) => {},
glfwWaitThread: (ID, waitmode) => 0,

// One single thread
glfwGetThreadID: () => 0,
Expand Down
5 changes: 5 additions & 0 deletions test/browser/test_glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ int main() {
glfwSetTime(0);
}

{
GLFWcursor* cur = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
printf("glfwCreateStandardCursor => %p\n", cur);
}

#if CLIENT_API == GLFW_OPENGL_ES_API
{
glfwMakeContextCurrent(window); // stub
Expand Down

0 comments on commit 677accc

Please sign in to comment.