Skip to content

Commit

Permalink
Allow BufferView indices to be unspecified.
Browse files Browse the repository at this point in the history
Allow BufferView indices for element array buffers to be unspecified to support some extensions.

Note that this is similar to how invalid array buffers are handled in order to support, for example, sparse morph targets.
  • Loading branch information
haroonq committed Oct 9, 2023
1 parent d59475b commit 17b6288
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6147,12 +6147,19 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,

const auto bufferView =
model->accessors[size_t(primitive.indices)].bufferView;
// bufferView could be null(-1) for certain extensions
if (bufferView >= 0 && bufferView < model->bufferViews.size()) {
if (bufferView < 0) {
// skip, bufferView could be null(-1) for certain extensions
} else if (size_t(bufferView) >= model->bufferViews.size()) {
if (err) {
(*err) += "accessor[" + std::to_string(primitive.indices) +
"] invalid bufferView";
}
return false;
} else {
model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER;
// we could optionally check if accessors' bufferView type is Scalar,
// as it should be
// we could optionally check if accessors' bufferView type is Scalar, as
// it should be
}
}

Expand Down

0 comments on commit 17b6288

Please sign in to comment.