Skip to content

Commit

Permalink
rust: Fix Unity loading
Browse files Browse the repository at this point in the history
The deku::byte_offset trick we do for alignment requires reader.bits_read to be correct, as that's the number we pad by. In our PackedVec implementations, we read a u8, and then later skip over it, which double-counts from the perspective of reader.bits_read. Fix this by adjusting after we read it.
  • Loading branch information
magcius committed Jan 24, 2025
1 parent 23261e5 commit 27bfe22
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rust/src/unity/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl<'a, Ctx> DekuReader<'a, Ctx> for Packedi32Vec where Ctx: Clone {
reader.seek(SeekFrom::Current(byte_array_count as i64)).unwrap();
let bit_size: u8 = u8::from_reader_with_ctx(reader, ())?;
reader.seek(SeekFrom::Current(-(byte_array_count as i64) - 1)).unwrap();
reader.bits_read -= 8;
let data = unpack_i32s(reader, num_items as usize, bit_size as usize)?;
reader.skip_bits(4 * 8)?; // bit_size, padding

Expand Down Expand Up @@ -255,6 +256,7 @@ impl<'a, Ctx> DekuReader<'a, Ctx> for Packedf32Vec where Ctx: Clone {
reader.seek(SeekFrom::Current(byte_array_count as i64)).unwrap();
let bit_size = u8::from_reader_with_ctx(reader, ())?;
reader.seek(SeekFrom::Current(-(byte_array_count as i64) - 1)).unwrap();
reader.bits_read -= 8;

let max = ((1 << bit_size) as f32) - 1.0;
let ints = unpack_i32s(reader, num_items as usize, bit_size as usize)?;
Expand Down

0 comments on commit 27bfe22

Please sign in to comment.