Skip to content

fix(extractor): duplicate asset-index entries race in loose output - #215

Merged
999sian merged 1 commit into
999sian:masterfrom
Strikeborn:fix/extractor-duplicate-entries
Oct 20, 2026
Merged

999sian merged 1 commit into
999sian:masterfrom
Strikeborn:fix/extractor-duplicate-entries

Conversation

@Strikeborn

Copy link
Copy Markdown

Result: loose extraction (the editable assets_src/ tree modders work in, and --loose-assets) is deterministic again, and matches the packed cache. The packed cache players use is unchanged: it already resolved duplicates deterministically.

Files: tools/src/assets_extractor/assets_extractor.hpp

Cause

The generated port/port_asset_index.c lists 9 paths twice, at the same offset but with different sizes: assets/*.json has per-region entries for those files and the generator keeps both. The tilemap, gfx and sweep passes extract every entry in parallel, so two threads write one loose file and the last to finish wins. Two runs of the same build produced different assets_src/ trees.

Packed output was never affected: PakBuilder::Write already sorts duplicates and keeps the largest. The room maps the game loads come from the area-table pass, which sizes each one by its real LZ stream, so they were correct either way. Picking the smaller copy would truncate three of these room maps (2, 21 and 15 bytes short of their stream), but those tilemaps/ copies aren't read at runtime.

Change

unique_asset_index_entries() resolves each path to one entry before any parallel work, keeping the largest, which is the same rule as PakBuilder::Write. Loose and packed output then agree, and packed output is byte-identical to before. The largest copy holds the full compressed stream for every duplicate (checked against the USA ROM). The single-threaded build_embedded_asset_lookup is left as is.

The generated index itself isn't edited: it says "DO NOT EDIT MANUALLY", and tools/generate_asset_index.py isn't in the repo. Since the index's offsets are USA-baseline, the generator could keep only the USA entry per path.

Tested

Windows, with retail USA, EU and JP ROMs (SHA-1s match tmc*.sha1):

Region Boots Packed cache, 2 cold launches Loose extraction, 3 runs Duplicates resolved to
USA yes identical identical (41,391 files) largest
EU yes identical identical (73,669 files) largest
JP yes identical identical (43,552 files) largest
  • Before: two loose USA runs differed in the duplicated files.
  • Linux (Ubuntu 26.04): loose extraction identical across 3 runs.
  • Play-tested to the Picori Festival on USA (early game only).

Developed with assistance from Claude Code (Opus 5.5). I reviewed and tested the changes as described above.

… extraction

Nine paths are indexed twice with different sizes, so loose extraction raced. Keep the largest, matching PakBuilder::Write, so loose output is deterministic and packed output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@999sian
999sian merged commit 0113453 into 999sian:master Oct 20, 2026
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.

2 participants