1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 10:44:07 +02:00

assert that reading uses the correct amount of bytes

This commit is contained in:
Robin Appelman 2022-02-20 16:38:30 +01:00
commit 9398ea7cf5
2 changed files with 12 additions and 1 deletions

View file

@ -299,6 +299,7 @@ pub struct Leaf {
pub leaf_face_count: u16,
pub first_leaf_brush: u16,
pub leaf_brush_count: u16,
#[br(pad_size_to = 4)]
pub leaf_watter_data_id: i16,
}

View file

@ -1,5 +1,6 @@
use crate::*;
use binrw::BinReaderExt;
use std::any::type_name;
use std::borrow::Cow;
use std::mem::size_of;
@ -44,7 +45,16 @@ impl<R: BinReaderExt + Read> LumpReader<R> {
where
T::Args: Default,
{
Ok(self.inner.read_le()?)
let start = self.inner.stream_position().unwrap() as usize;
let result = self.inner.read_le()?;
let end = self.inner.stream_position().unwrap() as usize;
debug_assert_eq!(
end - start,
size_of::<T>(),
"Incorrect number of bytes consumed while reading a {}",
type_name::<T>()
);
Ok(result)
}
pub fn read_visdata(&mut self) -> BspResult<VisData> {