vdb-rs icon indicating copy to clipboard operation
vdb-rs copied to clipboard

compressed_count = 0 causes panic

Open YorickdeJong opened this issue 1 year ago • 2 comments

Hi,

I tried to run the bevy example in the library. I'm using macOS 13.3 and ran the following command:

cargo run --example bevy ~/Downloads/TornadoLoopingVDB/TornadoLooping/TornadoVDB/tornado_0000.vdb

This produces the following error:

thread 'Compute Task Pool (5)' panicked at /Users/yorickdejong/vdb-rs/src/reader.rs:240:17:
assertion `left == right` failed
 left: 0
right: 30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy::setup`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

It seems that the compressed count is 0, instead of 30:

    fn read_compressed_data<T: Pod>(
       reader: &mut R,
       _archive: &ArchiveHeader,
       gd: &GridDescriptor,
       count: usize,
   ) -> Result<Vec<T>, ParseError> {
       Ok(if gd.compression.contains(Compression::BLOSC) {
           let num_compressed_bytes = reader.read_i64::<LittleEndian>()?;
           let compressed_count = num_compressed_bytes / std::mem::size_of::<T>() as i64;

           trace!("Reading blosc data, {} bytes", num_compressed_bytes);
           if num_compressed_bytes <= 0 {
               let mut data = vec![T::zeroed(); (-compressed_count) as usize];
               reader.read_exact(cast_slice_mut(&mut data))?;
               assert_eq!(-compressed_count as usize, count);
               data

The vdb file can be downloaded from this link (it's the tornado): https://jangafx.com/software/embergen/download/free-vdb-animations/

YorickdeJong avatar Feb 01 '24 20:02 YorickdeJong

This is supposed to mimic the code in https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb%2Fopenvdb%2Fio%2FCompression.cc pretty much exactly, if it doesn't then that's a bug.

Feel free to contribute a patch by opening a pull request!

Jasper-Bekkers avatar Feb 01 '24 21:02 Jasper-Bekkers

Hi @Jasper-Bekkers,

Thanks, will open a pull request when I'm done with the patch

Best, Yorick

YorickdeJong avatar Feb 02 '24 16:02 YorickdeJong