batch_glb: try a same-stem DDS when the preferred PNG cannot be read #1751

Merged
kirigayakazima merged 2 commits from upstream-pr/1751 into main 2026-11-28 14:56:46 +00:00
kirigayakazima commented 2026-11-25 11:14:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T11:14:28Z.


Claimed in the coordination issue as: BATCH-GLB-DDS-SIBLING-FALLBACK

What and why

Texture indexing kept only the preferred PNG for a stem. An empty or unreadable PNG therefore stripped the material's texture even if a usable DDS sat beside it. The index now retains candidates in preference order. Conversion records the failed PNG and tries the DDS for the same stem. A readable PNG still wins.

Tested

The synthetic OBJ uses UVs and a material shared by a PNG and DDS with distinct pixel values. The regression checks the actual embedded image bytes with a usable preferred PNG and again with an empty PNG. On the baseline the DDS image was absent in the second run.

  • python -I tests/test_batch_glb.py passed all 17 tests on this branch (Windows, Python 3.14.7).
  • git diff --check and the repository game-data scan of all changed paths passed.
  • The five independent changes were also merged locally. Both affected test files passed together (50 tests) and the three character-model consumer suites passed (28 tests). The shared base at bcaa13da passed 6,287 semantic tests across 488 files.

GPUs tested: N/A (CPU-only asset tooling).
AI-assisted: Yes.

Checklist

  • Based on current upstream main.
  • One topic.
  • Only synthetic test fixtures. No game data, keys or decryption.
  • Translator contract table: N/A.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5490252090 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1751). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T11:14:28Z. --- Claimed in the coordination issue as: [BATCH-GLB-DDS-SIBLING-FALLBACK](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7160621714) ### What and why Texture indexing kept only the preferred PNG for a stem. An empty or unreadable PNG therefore stripped the material's texture even if a usable DDS sat beside it. The index now retains candidates in preference order. Conversion records the failed PNG and tries the DDS for the same stem. A readable PNG still wins. ### Tested The synthetic OBJ uses UVs and a material shared by a PNG and DDS with distinct pixel values. The regression checks the actual embedded image bytes with a usable preferred PNG and again with an empty PNG. On the baseline the DDS image was absent in the second run. - `python -I tests/test_batch_glb.py` passed all 17 tests on this branch (Windows, Python 3.14.7). - `git diff --check` and the repository game-data scan of all changed paths passed. - The five independent changes were also merged locally. Both affected test files passed together (50 tests) and the three character-model consumer suites passed (28 tests). The shared base at `bcaa13da` passed 6,287 semantic tests across 488 files. GPUs tested: N/A (CPU-only asset tooling). AI-assisted: Yes. ### Checklist - [x] Based on current upstream main. - [x] One topic. - [x] Only synthetic test fixtures. No game data, keys or decryption. - Translator contract table: N/A.
lixonik commented 2026-11-25 11:19:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T11:19:58Z.

Review: COMMENTED


Independent check at "a0957dcd". Windows: all 17 batch tests passed, including the empty-PNG fallback. A readable but malformed PNG still won over a usable sibling DDS in a separate synthetic conversion. Details inline.

AI-assisted review and CPU-only testing with synthetic inputs.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6056672434 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1751#pullrequestreview-6056672434). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T11:19:58Z. **Review:** COMMENTED --- Independent check at "a0957dcd". Windows: all 17 batch tests passed, including the empty-PNG fallback. A readable but malformed PNG still won over a usable sibling DDS in a separate synthetic conversion. Details inline. AI-assisted review and CPU-only testing with synthetic inputs.
lixonik commented 2026-11-25 11:19:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T11:19:58Z.

Code review location: tools/batch_glb.py; line 129

@@ -124,13 +123,10 @@ def convert_single(
                     f"{clean_stem}_diff",
                 ])
 
-                found_path = None
-                for key in lookup_keys:
-                    if key in tex_index:
-                        found_path = tex_index[key]
-                        break
-
-                if found_path:
+                candidates = next((tex_index[key] for key in lookup_keys if key in tex_index), [])
+                if isinstance(candidates, str):
+                    candidates = [candidates]   # callers may supply a single path for each stem
+                for found_path in candidates:

The fallback still stops at a corrupt PNG if the file is readable and nonempty. I used a preferred PNG with a valid signature but truncated contents and a usable same-stem DDS. Conversion reported success, embedded the truncated bytes as image/png, and produced neither a warning nor the DDS image. The candidate loop sees any nonempty PNG bytes as success. Could the loader validate the preferred PNG enough to reject corruption before deciding whether to try the sibling?

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4694122826 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1751#discussion_r4694122826). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T11:19:58Z. **Code review location:** `tools/batch_glb.py`; line 129 ~~~~diff @@ -124,13 +123,10 @@ def convert_single( f"{clean_stem}_diff", ]) - found_path = None - for key in lookup_keys: - if key in tex_index: - found_path = tex_index[key] - break - - if found_path: + candidates = next((tex_index[key] for key in lookup_keys if key in tex_index), []) + if isinstance(candidates, str): + candidates = [candidates] # callers may supply a single path for each stem + for found_path in candidates: ~~~~ --- The fallback still stops at a corrupt PNG if the file is readable and nonempty. I used a preferred PNG with a valid signature but truncated contents and a usable same-stem DDS. Conversion reported success, embedded the truncated bytes as image/png, and produced neither a warning nor the DDS image. The candidate loop sees any nonempty PNG bytes as success. Could the loader validate the preferred PNG enough to reject corruption before deciding whether to try the sibling?
ZroIsHere commented 2026-11-26 01:15:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ZroIsHere on 2026-11-26T01:15:07Z.


I addressed the corrupt-but-readable PNG case from the review in a stacked draft follow-up: https://github.com/kirigayakazima/leonida-continued/pull/1

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7179585295 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1751#issuecomment-7179585295). Originally posted by [ZroIsHere](https://github.com/ZroIsHere) on 2026-11-26T01:15:07Z. --- I addressed the corrupt-but-readable PNG case from the review in a stacked draft follow-up: https://github.com/kirigayakazima/leonida-continued/pull/1
kirigayakazima commented 2026-11-27 12:09:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:09:52Z.

Code review location: tools/batch_glb.py; line 129

@@ -124,13 +123,10 @@ def convert_single(
                     f"{clean_stem}_diff",
                 ])
 
-                found_path = None
-                for key in lookup_keys:
-                    if key in tex_index:
-                        found_path = tex_index[key]
-                        break
-
-                if found_path:
+                candidates = next((tex_index[key] for key in lookup_keys if key in tex_index), [])
+                if isinstance(candidates, str):
+                    candidates = [candidates]   # callers may supply a single path for each stem
+                for found_path in candidates:

Fixed: added PNG signature, IHDR/IDAT/IEND framing, and per-chunk CRC32 validation in tools/batch_glb.py so truncated or corrupt preferred PNGs fall back cleanly to their sibling DDS with diagnostic reporting. Added truncated-PNG fallback coverage in tests/test_batch_glb.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4719193840 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1751#discussion_r4719193840). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-27T12:09:52Z. **Code review location:** `tools/batch_glb.py`; line 129 ~~~~diff @@ -124,13 +123,10 @@ def convert_single( f"{clean_stem}_diff", ]) - found_path = None - for key in lookup_keys: - if key in tex_index: - found_path = tex_index[key] - break - - if found_path: + candidates = next((tex_index[key] for key in lookup_keys if key in tex_index), []) + if isinstance(candidates, str): + candidates = [candidates] # callers may supply a single path for each stem + for found_path in candidates: ~~~~ --- Fixed: added PNG signature, IHDR/IDAT/IEND framing, and per-chunk CRC32 validation in `tools/batch_glb.py` so truncated or corrupt preferred PNGs fall back cleanly to their sibling DDS with diagnostic reporting. Added truncated-PNG fallback coverage in `tests/test_batch_glb.py`.
lixonik commented 2026-11-27 15:50:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:50:25Z.

Review: COMMENTED


Re-verified at 2689c7f5b (merged cleanly onto main ec91d695c).

  • Confirmed the prior finding is resolved: _validate_png_bytes() validates the PNG signature, chunk framing, per-chunk CRC32, IHDR length/dimensions, IDAT presence, and empty IEND with no trailing data, so corrupt or truncated preferred PNGs fall back to a sibling DDS while retaining the PNG diagnostic. Checked additional synthetic corrupt inputs (bad CRC, trailing bytes after IEND, missing IDAT, zero IHDR dimension, truncated header) directly.
  • Windows 11, Python 3.12: python -I -B tests/test_batch_glb.py -v passed (17/17); scripts/check_no_game_data.py and git diff --check clean.
  • No remaining findings.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6090597534 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1751#pullrequestreview-6090597534). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:50:25Z. **Review:** COMMENTED --- Re-verified at `2689c7f5b` (merged cleanly onto `main` `ec91d695c`). - Confirmed the prior finding is resolved: `_validate_png_bytes()` validates the PNG signature, chunk framing, per-chunk CRC32, `IHDR` length/dimensions, `IDAT` presence, and empty `IEND` with no trailing data, so corrupt or truncated preferred PNGs fall back to a sibling DDS while retaining the PNG diagnostic. Checked additional synthetic corrupt inputs (bad CRC, trailing bytes after `IEND`, missing `IDAT`, zero `IHDR` dimension, truncated header) directly. - Windows 11, Python 3.12: `python -I -B tests/test_batch_glb.py -v` passed (17/17); `scripts/check_no_game_data.py` and `git diff --check` clean. - No remaining findings. AI-assisted.
zmasi commented 2026-11-28 11:38:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:38:19Z.


#1751 | head 2689c7f5ba (merged cleanly with main 4a54aedcb) | python -I tests/test_batch_glb.py | red on main: FAILED (failures=2) (empty_png and truncated_png subtests failed to fall back to same-stem DDS and embedded truncated PNG bytes) | green on PR+main: 17 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited _build_texture_index, _validate_png_bytes, and convert_single in tools/batch_glb.py (validating PNG signature, chunk bounds/CRC32, IHDR dimensions, IDAT presence, and IEND framing, retaining the failed PNG diagnostic in dropped while falling back to a same-stem .dds, and preserving single-path tex_index compatibility). Also verified clean merge (0 conflicts) and combined execution with #1752 (19 tests OK; note a trivial import-block context overlap in tools/batch_glb.py if merged alongside #1750), plus tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238683706 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1751#issuecomment-7238683706). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:38:19Z. --- #1751 | head 2689c7f5ba095d03a96df7db4d046d7efad40fe2 (merged cleanly with main 4a54aedcb) | `python -I tests/test_batch_glb.py` | red on main: `FAILED (failures=2)` (`empty_png` and `truncated_png` subtests failed to fall back to same-stem DDS and embedded truncated PNG bytes) | green on PR+main: `17 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `_build_texture_index`, `_validate_png_bytes`, and `convert_single` in `tools/batch_glb.py` (validating PNG signature, chunk bounds/CRC32, `IHDR` dimensions, `IDAT` presence, and `IEND` framing, retaining the failed PNG diagnostic in `dropped` while falling back to a same-stem `.dds`, and preserving single-path `tex_index` compatibility). Also verified clean merge (`0` conflicts) and combined execution with #1752 (`19 tests OK`; note a trivial `import`-block context overlap in `tools/batch_glb.py` if merged alongside #1750), plus `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 14:56:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:56:44Z.


Red/green: pytest tests/test_batch_glb.py fails on main (2 failed, 17 passed, 12 subtests passed) and passes on head 2689c7f5ba merged with main (17 passed, 14 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241058518 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1751#issuecomment-7241058518). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:56:44Z. --- Red/green: `pytest tests/test_batch_glb.py` fails on main (2 failed, 17 passed, 12 subtests passed) and passes on head 2689c7f5ba09 merged with main (17 passed, 14 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1751
No description provided.