Skip to content

Fix: update() called before setup() on startup#27

Draft
triss wants to merge 1 commit into
L5lua:mainfrom
triss:fix/26-update-before-setup
Draft

Fix: update() called before setup() on startup#27
triss wants to merge 1 commit into
L5lua:mainfrom
triss:fix/26-update-before-setup

Conversation

@triss

@triss triss commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Fixes #26

  • love.update(dt) ran on startup and triggered user's update() before setup() had been run. This meant state initialised in setup() may not have been ready for update.

Lifecycle of applications should be:

setup()
update()
draw()
...

not

update()
setup()
draw()
update()

Solution

  • Split love.update(dt)'s per-frame framework bookkeeping (mouse position, deltaTime, key, video looping) into a new L5_internal.updateFrameState(dt), which still runs unconditionally every frame - including the frame setup() runs on - so that state stays live during setup() exactly as before.
  • The user's update() callback now lives in the same branch as draw(), which is only reached once setup() has completed - so update() naturally can't fire before setup(), with no flag needing to be shared across functions.

Test plan

  • Reproduced the reported error (attempt to perform arithmetic on global 'v' (a nil value)) on pre-fix code using the issue's exact repro script run via love
  • Confirmed the same script runs cleanly post-fix, with setup() completing before update() fires
  • Confirmed mouseX, mouseY, deltaTime, and key are still live (non-default/non-nil) inside setup()
  • Ran the repo's main.lua example sketch to confirm no regression in normal draw-loop behavior
  • Confirm change doesn't break other examples

@triss
triss force-pushed the fix/26-update-before-setup branch from 1282ecd to 78af256 Compare July 23, 2026 11:32
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 L5lua#26

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@triss
triss force-pushed the fix/26-update-before-setup branch from 78af256 to f46e457 Compare July 23, 2026 12:55
@triss
triss marked this pull request as ready for review July 23, 2026 15:27
@triss
triss marked this pull request as draft July 23, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lifecycle issue: update() called before setup() upon startup

1 participant