Skip to content

Commit

Permalink
Merge pull request #205 from EmbarkStudios/byte-stride-fix
Browse files Browse the repository at this point in the history
Fix assert on meshes on byte_stride = 0
  • Loading branch information
alteous authored Feb 28, 2019
2 parents 5d9ac9e + 8f29c6c commit 4e68a75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/accessor/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a, T> Iter<'a, T> {
debug_assert!(mem::size_of::<T>() > 0);
let view = accessor.view();
let stride = view.stride().unwrap_or(mem::size_of::<T>());
debug_assert!(stride >= mem::size_of::<T>());
debug_assert!(stride >= mem::size_of::<T>(), "Mismatch in stride, expected at least {} stride but found {}", mem::size_of::<T>(), stride);
let start = view.offset() + accessor.offset();
let end = start + stride * (accessor.count() - 1) + mem::size_of::<T>();
let data = &buffer_data[start .. end];
Expand Down
10 changes: 9 additions & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ impl<'a> View<'a> {
/// Returns the stride in bytes between vertex attributes or other interleavable
/// data. When `None`, data is assumed to be tightly packed.
pub fn stride(&self) -> Option<usize> {
self.json.byte_stride.map(|x| x.0 as usize)
self.json.byte_stride.and_then(|x| {
// Treat byte_stride == 0 same as not specifying stride.
// This is technically a validation error, but best way we can handle it here
if x.0 == 0 {
None
} else {
Some(x.0 as usize)
}
})
}

/// Optional user-defined name for this object.
Expand Down

0 comments on commit 4e68a75

Please sign in to comment.