fix: wait for async refreshSize before reading GPU dimensions
This commit is contained in:
@@ -43,16 +43,30 @@ local function findGPU()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function makeGpuBackend(gpu)
|
local function makeGpuBackend(gpu)
|
||||||
|
-- refreshSize() is async: it schedules the monitor-wall scan on the
|
||||||
|
-- server thread and returns immediately. Poll until blocksX or
|
||||||
|
-- blocksY grows, or we time out (2 s).
|
||||||
gpu.refreshSize()
|
gpu.refreshSize()
|
||||||
-- Try a high per-block resolution; older/cheaper GPU tiers may cap
|
local pw, ph, bx, by, sb
|
||||||
-- this so fall back if it errors.
|
local deadline = os.clock() + 2
|
||||||
|
repeat
|
||||||
|
sleep(0.1)
|
||||||
|
pw, ph, bx, by, sb = gpu.getSize()
|
||||||
|
until ((bx or 0) > 1 or (by or 0) > 1) or os.clock() >= deadline
|
||||||
|
|
||||||
|
-- If still 1x1 try once more after a longer wait, then proceed anyway.
|
||||||
|
if (bx or 0) <= 1 and (by or 0) <= 1 then
|
||||||
|
sleep(0.5)
|
||||||
|
pw, ph, bx, by, sb = gpu.getSize()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Try a high per-block resolution; fall back if GPU tier caps it.
|
||||||
local trySizes = { 64, 32, 16, 8 }
|
local trySizes = { 64, 32, 16, 8 }
|
||||||
for _, s in ipairs(trySizes) do
|
for _, s in ipairs(trySizes) do
|
||||||
if pcall(gpu.setSize, s) then break end
|
if pcall(gpu.setSize, s) then break end
|
||||||
end
|
end
|
||||||
|
-- Re-read size after setSize (pixel dimensions change).
|
||||||
-- getSize() returns: pixelW, pixelH, blocksX, blocksY, sizePerBlock
|
pw, ph, bx, by, sb = gpu.getSize()
|
||||||
local pw, ph, bx, by, sb = gpu.getSize()
|
|
||||||
print(("[roulette] GPU pixel size: %sx%s blocks: %sx%s per-block: %s")
|
print(("[roulette] GPU pixel size: %sx%s blocks: %sx%s per-block: %s")
|
||||||
:format(tostring(pw), tostring(ph), tostring(bx), tostring(by), tostring(sb)))
|
:format(tostring(pw), tostring(ph), tostring(bx), tostring(by), tostring(sb)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user