Skip to content

Commit

Permalink
Add test for values read in sparse accessor without buffer view
Browse files Browse the repository at this point in the history
This test triggers an infinite loop, as `next()` in `SparseIter`
does not have any end condition whenever the base buffer view
is not set in a sparse accessor.
  • Loading branch information
derwiath committed Jan 8, 2024
1 parent f57d145 commit 263af2a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,23 @@ fn test_sparse_accessor_without_base_buffer_view_yield_exact_size_hints() {
outputs_iter.next();
}
}

#[test]
fn test_sparse_accessor_without_base_buffer_view_yield_all_values() {
let (document, buffers, _) = gltf::import(BOX_SPARSE_GLTF).unwrap();

let animation = document.animations().next().unwrap();
let sampler = animation.samplers().next().unwrap();
let output_accessor = sampler.output();
let output_iter = gltf::accessor::Iter::<f32>::new(output_accessor, |buffer: gltf::Buffer| {
buffers.get(buffer.index()).map(|data| &data.0[..])
})
.unwrap();
let outputs = output_iter.collect::<Vec<_>>();

const EXPECTED_OUTPUTS: [f32; 2] = [0.0, 1.0];
assert_eq!(outputs.len(), EXPECTED_OUTPUTS.len());
for (i, o) in outputs.iter().enumerate() {
assert_eq!(o - EXPECTED_OUTPUTS[i], 0.0);
}
}

0 comments on commit 263af2a

Please sign in to comment.