Skip to content

glb_writer: validate instance transform component counts - #4905

Open
XFlawless1 wants to merge 1 commit into
ItsNotRexed:mainfrom
XFlawless1:fix/instance-transform-widths
Open

XFlawless1 wants to merge 1 commit into
ItsNotRexed:mainfrom
XFlawless1:fix/instance-transform-widths

Conversation

@XFlawless1

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue.

What and why

build_instanced_glb(..., mode="nodes") could serialize four-component translation or scale arrays, producing invalid glTF. Short scales raised IndexError; malformed rotations could escape as a raw ValueError. The glTF node schema requires exactly three translation/scale components and four rotation components.

Check the component counts before normalization, scale indexing, bounds, or serialization in both instancing modes. Each refusal is a GlbError naming the field and required count. Tests cover malformed vectors, preservation of an existing output, absence of partial output, iterator inputs, and quaternion normalization.

Tested

The initial regression cases failed on unchanged main (12 failures, 8 errors).

  • 181 focused tests completed: world instancing (35), GLB writer (70), buffer validation (2), atomic writes (12), world build (59), and text line endings (3). 180 passed; one platform-specific atomic-write test was skipped on Linux.
  • Full translator regression suite: 6,245 tests ran, with 3 failures and 2 errors in test_loop_ballot_barrier.py (plus 4 skips and 1 expected failure). Running that complete 15-test module on a pristine 594f3485 worktree reproduces the same failures and errors. These are the stale wave64 expectations and missing interpreter function-call support addressed by existing PR #4808.
  • python3 -m compileall -q make_game.py tools tests, isolated make_game.py --help, and git diff --check passed.

Tested on Linux x86_64, Python 3.14.4, against upstream main 594f3485. CPU only; no GPU or driver used. Windows was not tested locally. All geometry and transforms are synthetic.

The published branch starts at fork main 16282101; its world-instancing suite also passes (30 tests). Its merge onto 594f3485 produces tree dfd6fa7c863070d85ed3836fd3372209a05675f1, exactly the tested tree (git merge-tree --write-tree). The PR changes only the writer and its instancing tests.

AI-assisted: yes (Codex).

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator changes.)

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows CPU placement check, AI-assisted, with uv CPython 3.12.13. Exact head, main d974c88a and their clean dry merge eb3d5732 each passed four new synthetic cases (node and GPU-instanced exports, list and one-shot iterator inputs). Two instances used different translations, asymmetric scales and non-unit quaternions. All 16 decoded corners per case matched the analytic transforms. Within each mode the list and iterator GLBs were byte-identical.

The older fork head still computes GPU-instance bounds before float32 packing, giving a maximum discrepancy of 1.71e−7 units on this fixture. The dry merge preserves upstream’s bounds from the stored transforms and agrees with the decoded geometry within 1e−12. Seven focused stock tests passed on the merged tree. Synthetic data only.

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS. New tests on current main fail 20 times, so they bite. The count check sits at tools/glb_writer.py:1183-1185, before normalization, scale indexing and packing, in both modes. Synthetic malformed counts all raise GlbError naming the field and count; the write path leaves no partial output and keeps an existing GLB intact. A real merge onto d974c88a is clean even though main moved 148 lines in glb_writer.py since the fork point, and the merged tree passes 178 tests.

Minor, out of scope: non-3-slot transforms and non-numeric values still escape as raw ValueError/TypeError.

Approve. AI-assisted review, no game files.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 7fd67ae merged with main 3faac55 on Linux (WSL2) / CPython 3.12.16: pass.

python -I tests/test_world_instancing.py: 35 run, 35 passed, 0 failed. Also test_glb_writer.py (70), test_glb_writer_buffers.py (2), test_instance_lists.py (16), test_batch_glb.py (11), test_glb_atomic.py (12, 1 skipped): all OK. Negative control: with tools/glb_writer.py checked out from main, test_world_instancing.py gives 35 run, 12 failures + 8 errors (the new transform-count subtests, mostly wrong-length components passing silently or raising a different error). The only non-test caller of build_instanced_glb is write_instanced_glb in the same file. No GPU or Windows run.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55: clean merge; all 35 tests in tests/test_world_instancing.py (including the three new ones: exact 3/4/3 component counts, no publish/replace of a GLB on invalid instances, iterator inputs plus rotation normalization) and the 70-test test_glb_writer regression pass under python -I (re-run). Main has no equivalent instance-transform check. CI pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 7fd67ae on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_world_instancing.py -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

6 participants