diff --git a/inventoryManager.lua b/inventoryManager.lua index bcba147..a923b82 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -75,9 +75,11 @@ local statusTimer = 0 -- Touch zones: list of {x1, y1, x2, y2, action, data} local touchZones = {} +local pendingZones = {} -- built during draw, swapped in at end +local needsRedraw = false local function addZone(x1, y1, x2, y2, action, data) - table.insert(touchZones, { + table.insert(pendingZones, { x1 = x1, y1 = y1, x2 = x2, y2 = y2, action = action, data = data }) @@ -147,7 +149,7 @@ local function drawDashboard() if not mon then return end local w, h = mon.getSize() - touchZones = {} + pendingZones = {} -- Create offscreen buffer (invisible) draw = window.create(mon, 1, 1, w, h, false) @@ -318,6 +320,9 @@ local function drawDashboard() -- Flush buffer to monitor in one go draw.setVisible(true) + + -- Swap touch zones atomically (no yield between these two lines) + touchZones = pendingZones end ------------------------------------------------- @@ -429,7 +434,10 @@ end local function handleTouch(x, y) local action, data = hitTest(x, y) - if not action then return end + if not action then + print("[TOUCH] No zone hit") + return + end if action == "amount" then selectedAmount = data @@ -449,8 +457,8 @@ local function handleTouch(x, y) print("[UI] Manual refresh") end - -- Redraw immediately after touch - pcall(drawDashboard) + -- Flag redraw instead of drawing here (avoids yielding in touch handler) + needsRedraw = true end ------------------------------------------------- @@ -498,10 +506,16 @@ local function main() function() while true do pcall(drawDashboard) + needsRedraw = false if statusTimer > 0 then - statusTimer = statusTimer - DASH_REFRESH + statusTimer = statusTimer - 1 + end + -- Short sleep so redraws triggered by touch happen quickly + local elapsed = 0 + while elapsed < DASH_REFRESH and not needsRedraw do + sleep(0.5) + elapsed = elapsed + 0.5 end - sleep(DASH_REFRESH) end end,