Skip to content

Fix data corruption by updating region label storage from u16 to u32#8

Merged
Vianpyro merged 2 commits intomainfrom
fix/silent_data_corruption_above_65535_regions
Mar 6, 2026
Merged

Fix data corruption by updating region label storage from u16 to u32#8
Vianpyro merged 2 commits intomainfrom
fix/silent_data_corruption_above_65535_regions

Conversation

@Vianpyro
Copy link
Copy Markdown
Member

@Vianpyro Vianpyro commented Mar 5, 2026

No description provided.

@Vianpyro Vianpyro self-assigned this Mar 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the chunk payload encoding in the world save format to prevent region label truncation/corruption by storing per-tile region labels as u32 rather than u16.

Changes:

  • Write per-tile region_label as 4 bytes (little-endian u32) in chunk payloads.
  • Read per-tile region_label as 4 bytes (little-endian u32) when loading chunks.
  • Update top-of-file format documentation to reflect 8 bytes/tile chunk storage.
Comments suppressed due to low confidence (1)

src/save.rs:219

  • raw is now populated with 8 bytes per tile (1 terrain + 2 elevation + 4 region label + 1 biome), but the preallocation is still sized for the old 6-bytes/tile layout. Update the Vec::with_capacity(...) multiplier to avoid avoidable reallocations while encoding chunks.
                    raw.extend_from_slice(&(data.region_labels[idx] as u32).to_le_bytes());

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@Vianpyro Vianpyro merged commit 462fe1c into main Mar 6, 2026
4 of 5 checks passed
@Vianpyro Vianpyro deleted the fix/silent_data_corruption_above_65535_regions branch March 6, 2026 13:24
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