Skip to content

Commit 845421e

Browse files
committed
Fix windows regressions
As I hoped, none of the changes broke windows specifically, beyond just the untested change to lazily fetched GL functions to avoid having to require the GL library at runtime which was nasty. Beyond that, I just needed to support a consistent way for windows to trigger a "create" event. Right now both the callback and the window aren't registered in the eventloop when the WM_CREATE real event is fired, so I couldn't use that, in the future I'll investigate ways to try to mitigate this but it's difficult.
1 parent f298e52 commit 845421e

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/bindings/gl.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ else
104104
function fetchNonCoreFn(name)
105105
local cached
106106

107-
return function(a, b, c, d, e, f, g, h, i, j)
107+
-- todo: investigate if using varargs here will cause jit to fail
108+
return function(...)
108109
if cached then
109-
return cached(a, b, c, d, e, f, g, h, i, j)
110+
return cached(...)
110111
end
111112

112113
local fn = ffi.cast(nonCoreFnDefs[name], wgl.getProcAddress(name))
@@ -115,7 +116,7 @@ else
115116
end
116117

117118
cached = fn
118-
return fn(a, b, c, d, e, f, g, h, i, j)
119+
return fn(...)
119120
end
120121
end
121122
end

src/window/win32.lua

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ end
8686
---@field currentMode "poll" | "wait"
8787
---@field handler EventHandler
8888
---@field callback fun(event: Event, handler: EventHandler)
89-
---@field pendingCreates table<number, boolean>
9089
local Win32EventLoop = {}
9190
Win32EventLoop.__index = Win32EventLoop
9291

@@ -97,23 +96,14 @@ function Win32EventLoop.new()
9796
end
9897

9998
local class = user32.newWndClassEx()
100-
local self = setmetatable({
101-
class = class,
102-
windows = {},
103-
pendingCreates = {},
104-
}, Win32EventLoop)
99+
local self = setmetatable({ class = class, windows = {} }, Win32EventLoop)
105100

106101
class.lpszClassName = "ArisuWindow"
107102
class.lpfnWndProc = user32.newWndProc(function(hwnd, msg, wParam, lParam)
108103
if not self.callback then
109104
return user32.defWindowProc(hwnd, msg, wParam, lParam)
110105
end
111106

112-
if msg == user32.WM_CREATE then
113-
self.pendingCreates[util.toPointer(hwnd)] = true
114-
return 0
115-
end
116-
117107
local window = self.windows[util.toPointer(hwnd)]
118108

119109
if not window then
@@ -199,13 +189,6 @@ end
199189
---@param window Win32Window
200190
function Win32EventLoop:register(window)
201191
self.windows[window.id] = window
202-
203-
if self.pendingCreates[window.id] then
204-
self.callback({ name = "create", window = window }, self.handler)
205-
self.callback({ name = "map", window = window }, self.handler)
206-
207-
self.pendingCreates[window.id] = nil
208-
end
209192
end
210193

211194
---@param window Win32Window
@@ -228,6 +211,10 @@ function Win32EventLoop:run(callback)
228211
return ok
229212
end
230213

214+
for _, window in pairs(self.windows) do
215+
self.callback({ name = "create", window = window }, self.handler)
216+
end
217+
231218
local msg = user32.newMsg()
232219
while self.isActive do
233220
if self.currentMode == "poll" then

0 commit comments

Comments
 (0)