Skip to content

world_build: a non-integer lod_level is a malformed placement, not a TypeError in --lod-sets - #5979

Closed
cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:world-build-lod-level-int
Closed

cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:world-build-lod-level-int

Conversation

@cynbun

@cynbun cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #5934 (comment) (ProbablySyd's finding #5934 (comment), thanks for the report and repro).

Cause

Both placement readers select a row with row.get("lod_level") in levels (tools/world_build.py:128 in load_placements, :172 in iter_placements at 561b65a). Because 0.0 == 0 and True == 1, a float or bool level is accepted as the integer level. With --lod-sets, _build_instanced_world then appends that value to its array("b") tier array (inst_tier.append(lvl if lod_sets else 0), :596). A float raises TypeError: 'float' object cannot be interpreted as an integer, and one row stops the whole build before anything is written. Without --lod-sets, the same rows were placed silently (true in the LOD tier when 1 is selected), and "0" was counted as other_lod_level.

Rule

lodLevel is a u8 (docs/world.md, CEntityDef table: +0x7e | u8). world_index.py --entities-out writes the value _value() returns for that member, which is a Python int (or null when the member is absent). The format therefore promises an integer, and any other type is a damaged row rather than a level to normalise. The change:

  • One shared helper, _lod_level_selected(value, levels), used by both readers, like _parse_archetype, so they stay in step. It raises for any non-integer lod_level (float, bool, string, list, ...), and the readers count that row under the existing malformed counter. Unhashable values were already malformed; this extends the rule to every non-integer.
  • A missing/null lod_level keeps its current behaviour (other_lod_level).
  • Nothing in _build_instanced_world changes. The lines around :571-596 are left alone for ProbablySyd's claimed --lod-sets distance-sample change.

Tests

tests/test_world_instancing.py LodSetsTest.test_cli_counts_a_non_integer_lod_level_as_malformed: four synthetic placements with lod_level 0, 0.0, true and "0", built through world_build.main with --lod-levels 0,1, once with --lod-sets (iter_placements) and once with --instancing bake (load_placements). Both builds now exit 0 with rows 4, malformed 3, other_lod_level 0, selected 1, placed 1, and --lod-sets writes only c_hd_0_-1. On main, the --lod-sets run raises the TypeError above and the bake run counts (4, 0, 1, 3, 3).

Run on Linux, Python 3.14.8 (no GPU or game files needed): every tests/test_world*.py, tests/test_restofworld*.py and tests/test_text_write_line_endings.py with python -I pass; python -m compileall -q make_game.py tools tests and git diff --check are clean.

Overlap: merges cleanly (git merge-tree) with the open world_build PRs #5943, #5108, #5047, #4960 and #4433. #1981 folds both readers into one _select_placement, so it touches the same selected_lod line. Whichever lands second needs a one-line rebase (call _lod_level_selected there).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…TypeError in --lod-sets

lodLevel is a u8 (docs/world.md) and world_index.py --entities-out writes
it as a JSON integer. Both placement readers selected a row with
`row.get("lod_level") in levels`, so 0.0 and true matched 0 and 1. With
--lod-sets, _build_instanced_world then appended the float to its integer
tier array (array("b")) and the whole build stopped with a TypeError;
without it, the rows were placed (true in the LOD tier) and "0" was
counted as another LOD level.

One shared check, _lod_level_selected, now raises for any lod_level that
is not a JSON integer (bool excluded) and both readers count the row
under the existing `malformed` counter. A missing (null) level stays
"other_lod_level" as before.

Reported by ProbablySyd on ItsNotRexed#5934.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing at the coordinator's request (#5934 (comment)): this finding is @ProbablySyd's (BUILD-1943). @ProbablySyd, if it's useful, the branch has a CLI test (LodSetsTest.test_cli_counts_a_non_integer_lod_level_as_malformed: 0, 0.0, true, "0" through both --lod-sets and --instancing bake) and a shared _lod_level_selected check — feel free to take any of it. AI-assisted (Claude Code).

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