Skip to content

WIP DO NOT MERGE Fix: save_map_binary wrote scenario_id prefix that C never reads#374

Open
eugenevinitsky wants to merge 1 commit into3.0from
ev/fix-map-binary-format
Open

WIP DO NOT MERGE Fix: save_map_binary wrote scenario_id prefix that C never reads#374
eugenevinitsky wants to merge 1 commit into3.0from
ev/fix-map-binary-format

Conversation

@eugenevinitsky
Copy link
Copy Markdown

Summary

save_map_binary wrote 16 bytes of scenario_id before sdc_track_index, but load_map_binary in C starts reading at sdc_track_index with no scenario_id. This misaligned all subsequent reads, causing segfaults when loading converted maps.

Also fixes Town10HD conversion failure (scenario_id was an int, not str).

Test plan

  • Convert carla_data maps with process_all_maps
  • Verify converted maps load without segfault
  • Verify existing carla_2D/carla maps still work

save_map_binary wrote 16 bytes of scenario_id before sdc_track_index,
but load_map_binary in C starts reading at sdc_track_index with no
scenario_id. This misaligned all subsequent reads, causing segfaults
when loading converted maps.

Also fixes Town10HD conversion failure (scenario_id was an int, not str).
Copilot AI review requested due to automatic review settings March 28, 2026 21:04
Copy link
Copy Markdown

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

Fixes a binary format mismatch between Python map conversion (save_map_binary) and the C loader (load_map_binary) that was misaligning reads and causing crashes when loading converted maps.

Changes:

  • Removed writing a 16-byte scenario_id string prefix in save_map_binary so the file starts with sdc_track_index, matching the C reader.
  • Avoided conversion-time failures when scenario_id isn’t a string by eliminating the .encode() path entirely (since the prefix is no longer written).

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

Comment on lines +802 to 806
# Note: C load_map_binary does NOT read a scenario_id prefix.
# Do not write one here or the binary will be misaligned.

# Write sdc_track_index
f.write(struct.pack("i", sdc_track_index))
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

This change alters the on-disk binary format (removing the 16-byte prefix). Please add a small regression test that writes a minimal map via save_map_binary and asserts the first bytes are sdc_track_index (i.e., no 16-byte offset) so this misalignment doesn’t get reintroduced later.

Copilot uses AI. Check for mistakes.
Comment on lines +802 to +803
# Note: C load_map_binary does NOT read a scenario_id prefix.
# Do not write one here or the binary will be misaligned.
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The note here is easy to misread as “scenario_id isn’t part of the binary at all”, but load_map_binary does read an int scenario_id per-entity. Consider rewording to explicitly say “the file must start with sdc_track_index (no 16-byte string prefix)” and/or reference pufferlib/ocean/drive/drive.h:1060 to prevent confusion.

Suggested change
# Note: C load_map_binary does NOT read a scenario_id prefix.
# Do not write one here or the binary will be misaligned.
# Binary layout note:
# The file must start with sdc_track_index (an int32), with NO 16-byte
# scenario_id string prefix. The corresponding C reader
# (load_map_binary in pufferlib/ocean/drive/drive.h:1060) reads
# scenario_id as an int per-entity, not as a file-level prefix. Writing
# any extra prefix here will misalign all subsequent reads.

Copilot uses AI. Check for mistakes.
@eugenevinitsky eugenevinitsky changed the title Fix: save_map_binary wrote scenario_id prefix that C never reads WIP DO NOT MERGE Fix: save_map_binary wrote scenario_id prefix that C never reads Mar 28, 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