From f46e457a12453c0a4eda26310caa0784a7e531d6 Mon Sep 17 00:00:00 2001 From: Tristan Strange Date: Thu, 23 Jul 2026 12:32:12 +0100 Subject: [PATCH] Fix: update() no longer fires before setup() completes on startup love.update(dt) ran unconditionally every frame, but setup() only ran later within the same frame's draw phase - so the user's update() callback could execute before setup() had a chance to initialize any state, causing nil errors on startup. Split the per-frame framework bookkeeping (mouse position, deltaTime, key, video looping) into L5_internal.updateFrameState(dt), which still runs unconditionally every frame including the one where setup() runs, so that state stays live during setup() as before. The user's update() callback now lives in the same branch as draw() - only reached once setup() has completed - so no flag needs to be shared across functions. Fixes #26 Co-Authored-By: Claude Sonnet 5 --- L5.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/L5.lua b/L5.lua index 02e7ba1..6d8bd84 100644 --- a/L5.lua +++ b/L5.lua @@ -51,9 +51,9 @@ function love.run() -- Update dt if love.timer then dt = love.timer.step() end - -- Update - if love.update then love.update(dt) end - + -- Update per-frame framework state (mouse position, deltaTime, key, video looping) + L5_internal.updateFrameState(dt) + -- Draw with double buffering if love.graphics and love.graphics.isActive() then love.graphics.origin() @@ -75,6 +75,7 @@ function love.run() setup() setupComplete = true else + if update ~= nil then update() end if love.draw then love.draw() end end @@ -164,7 +165,9 @@ function love.load() fill(255) end -function love.update(dt) +-- Per-frame framework bookkeeping (mouse position, deltaTime, key, video +-- looping) - runs every frame regardless of whether setup() has completed +function L5_internal.updateFrameState(dt) mouseX, mouseY = love.mouse.getPosition() movedX=mouseX-pmouseX movedY=mouseY-pmouseY @@ -182,9 +185,6 @@ function love.update(dt) end end end - - -- Optional update (not typically Processing-like but available) - if update ~= nil then update() end end function love.draw() @@ -849,7 +849,7 @@ function L5_internal.defaults() TRIANGLE_STRIP = "strip" -- global user vars - can be read by user but shouldn't be altered by user - key = "" --default, overriden with key presses detected in love.update(dt) + key = "" --default, overriden with key presses detected in L5_internal.updateFrameState(dt) width = 800 --default, overridden with size() or fullscreen() height = 600 --ditto frameCount = 0