Skip to content

Fix stack overflow from nested 'on ready' scripts#1779

Merged
alexwarren merged 2 commits into
mainfrom
fix/on-ready-stack-overflow
Jun 28, 2026
Merged

Fix stack overflow from nested 'on ready' scripts#1779
alexwarren merged 2 commits into
mainfrom
fix/on-ready-stack-overflow

Conversation

@alexwarren

Copy link
Copy Markdown
Contributor

Summary

  • AddOnReady was calling RunScriptAsync(callback) directly when _pendingCallbackCount == 0
  • If the callback (or anything it called) contained another on ready statement, that also saw count == 0 and called RunScriptAsync again — infinite mutual recursion between OnReadyScript.ExecuteAsyncAddOnReady, causing a stack overflow in prod
  • Fix: call BeginPendingCallback() before running the script so any nested on ready calls queue themselves; drain the queue via EndPendingCallbackAsync() after — the same Begin/End pattern used by WaitScript, ShowMenuScript, etc.

Bumps version to 6.0.0-beta.26.

Test plan

  • All 256 engine tests pass
  • Deploy and verify games with nested on ready calls (e.g. on ready inside an action triggered by another on ready) no longer stack overflow

🤖 Generated with Claude Code

alexwarren and others added 2 commits June 28, 2026 12:58
When _pendingCallbackCount was 0, AddOnReady called RunScriptAsync
directly. If the callback (or anything it called) contained another
'on ready' statement, that also saw count == 0 and called RunScriptAsync
again, creating infinite mutual recursion.

Fix: bump the pending count before running the callback so nested
'on ready' calls queue themselves rather than recurse, then drain
the queue via EndPendingCallbackAsync as normal. Same Begin/End
pattern used by WaitScript, ShowMenuScript, etc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that an 'on ready' encountered inside another 'on ready' callback
runs sequentially after the outer callback completes, not nested inside it.
This ordering difference is observable and would fail on the pre-fix code
(which ran inner callbacks immediately, producing "outer before" → "inner"
→ "outer after" instead of the correct "outer before" → "outer after" → "inner").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alexwarren alexwarren merged commit cb615a3 into main Jun 28, 2026
3 checks passed
@alexwarren alexwarren deleted the fix/on-ready-stack-overflow branch June 28, 2026 12:08
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.

1 participant