Skip to content

fix(headless): actually check readiness in pregenerateChunks - #5377

Open
soloturn wants to merge 1 commit into
developfrom
soloturn-fix-headless-pregenerate
Open

fix(headless): actually check readiness in pregenerateChunks#5377
soloturn wants to merge 1 commit into
developfrom
soloturn-fix-headless-pregenerate

Conversation

@soloturn

Copy link
Copy Markdown
Contributor

Fixes #5024 - PrepareWorld always waits the full 5 seconds in headless, regardless of how quickly the world is actually ready.

Root cause

PrepareWorld.step() loops until worldRenderer.pregenerateChunks() returns true or 5 seconds elapse. HeadlessWorldRenderer.pregenerateChunks() was an unimplemented stub:

@Override
public boolean pregenerateChunks() {
    // TODO Auto-generated method stub
    return false;
}

Always false means the loop only ever exits via the timeout, so every headless run - including every MTE integration test - burns the full 5 seconds here no matter how small or fast-generating the test world is.

Fix

Implemented it using the same chunk-loaded/local-view readiness check updateChunksInProximity() already performs for per-frame updates: advance chunkProvider, force a full rescan of the current view region, and report done once every chunk in it is loaded (chunkProvider.getChunk(pos) != null && worldProvider.getLocalView(pos) != null for each position) - mirroring what the graphical RenderableWorldImpl.pregenerateChunks() checks, minus the mesh-generation part that doesn't apply headless.

The rescan has to be forced. updateChunksInProximity's own "did the camera move" shortcut is keyed off chunkPos, which never changes in headless (NullCamera always reports the same position) - an unforced call would never re-examine chunk state and would permanently report "nothing pending" from its zero-value field default. That's a second, more subtle way to land on the same always-true-without-checking-anything failure mode as a bare return true, which is what @keturn's comment on the issue describes having already tried and found broke a following test.

Verification

:engine:compileJava clean. Ran the full engine-tests:integrationTest suite scoped to org.terasology.engine.integrationenvironment.* - 18 MTE test classes, 34 tests total, covering both per-class and per-method lifecycles, run back-to-back in the same JVM. This is the exact scenario keturn's earlier attempt broke ("first test fine, next one had problems"). All 34 pass, 0 failures, 0 errors.

No existing test exercises HeadlessWorldRenderer.pregenerateChunks() directly, only indirectly through the full MTE bootstrap above.

#5024: PrepareWorld.step() loops until worldRenderer.pregenerateChunks()
returns true or 5 seconds elapse. HeadlessWorldRenderer.pregenerateChunks()
was an unimplemented stub that always returned false, so headless runs
(including every MTE test) always burned the full 5 second wait
regardless of how quickly the world actually generated.

## Fix

Implemented pregenerateChunks() using the same chunk-loaded/local-view
check updateChunksInProximity() already performs for per-frame updates:
advance chunkProvider, force a full rescan of the current view region,
and report done once every chunk in it is loaded.

The rescan has to be forced: updateChunksInProximity's own
"did the camera move" shortcut is keyed off chunkPos, which never
changes in headless (NullCamera reports a constant position), so an
unforced call would never re-examine chunk state and permanently report
"nothing pending" from its zero-value default - a different way to end
up with the always-true failure mode keturn already ran into on a bare
`return true`, without ever confirming anything actually loaded.

## Verification

:engine:compileJava clean. Ran the full integrationenvironment test
suite (engine-tests:integrationTest, 18 MTE test classes covering
per-class and per-method lifecycles back-to-back in the same JVM,
34 tests total) - the exact scenario keturn's earlier attempt broke
("first test fine, next one had problems") - all 34 pass, 0 failures.

Fixes #5024

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Type: Bug Issues reporting and PRs fixing problems label Aug 19, 2026
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 687e2af1-1e38-4666-9d2e-e42ba402c079

📥 Commits

Reviewing files that changed from the base of the PR and between 338d7dd and 48143e1.

📒 Files selected for processing (1)
  • engine/src/main/java/org/terasology/engine/core/subsystem/headless/renderer/HeadlessWorldRenderer.java

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved headless world processing by ensuring pending chunks are detected and generated correctly.
    • Updated chunk availability checks to provide more accurate world initialization progress.

Walkthrough

The headless renderer now refreshes the chunk provider, forces a proximity-chunk scan within view distance, and reports whether chunk pre-generation has completed.

Changes

Headless chunk generation

Layer / File(s) Summary
Refresh and complete chunk pre-generation
engine/src/main/java/org/terasology/engine/core/subsystem/headless/renderer/HeadlessWorldRenderer.java
pregenerateChunks() refreshes the chunk provider, rescans chunks within view distance, and returns true when no chunks remain pending.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 48143

This localized fix makes headless world preparation stop once required chunks are ready instead of always waiting for the timeout. No actionable merge-blocking risk remains after normal checks and review.

Poem

I hop through chunks beneath the sky,
Refreshing worlds as time ticks by.
I scan the view from near to far,
Then signal when they ready are.
“No pending blocks!” I cheer and flee.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the headless readiness fix in pregenerateChunks.
Description check ✅ Passed The description clearly explains the bug, implementation, forced rescan requirement, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch soloturn-fix-headless-pregenerate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Issues reporting and PRs fixing problems

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

PrepareWorld step takes too long on headless

2 participants