Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assert on meshes on byte_stride = 0 #205

Merged
merged 2 commits into from Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/accessor/util.rs
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
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