Skip to content

Commit

Permalink
Added check for nullptr in GLTFSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuprynowicz committed Mar 2, 2024
1 parent 8e51664 commit 7780095
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libraries/model-serializers/src/GLTFSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ template<typename T> bool findPointerInArray(const T *pointer, const T *array, s
bool findAttribute(const QString &name, const cgltf_attribute *attributes, size_t numAttributes, size_t &index) {
std::string nameString = name.toStdString();
for (size_t i = 0; i < numAttributes; i++) {
if (strcmp(nameString.c_str(), attributes->name) == 0) {
index = i;
return true;
if (attributes->name == nullptr) {
qDebug(modelformat) << "GLTFSerializer: attribute with a null pointer name string";
} else {
if (strcmp(nameString.c_str(), attributes->name) == 0) {
index = i;
return true;
}
}
}
return false;
Expand Down Expand Up @@ -1072,15 +1076,15 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
size_t normalAttributeIndex = 0;
if (findAttribute("NORMAL", target.attributes, target.attributes_count, normalAttributeIndex)) {
if (!generateTargetData(target.attributes[normalAttributeIndex].data, weight, normals)) {
qWarning(modelformat) << "Invalid accessor type on generateTargetData vertices for model " << _url;
qWarning(modelformat) << "Invalid NORMAL accessor on generateTargetData vertices for model " << _url;
hfmModel.loadErrorCount++;
return false;
}
}
size_t positionAttributeIndex = 0;
if (findAttribute("POSITION", target.attributes, target.attributes_count, positionAttributeIndex)) {
if (!generateTargetData(target.attributes[positionAttributeIndex].data, weight, vertices)) {
qWarning(modelformat) << "Invalid accessor type on generateTargetData vertices for model " << _url;
qWarning(modelformat) << "Invalid POSITION accessor on generateTargetData vertices for model " << _url;
hfmModel.loadErrorCount++;
return false;
}
Expand Down

0 comments on commit 7780095

Please sign in to comment.