Fix OBJSerializer crash with empty groupMaterialName

This commit is contained in:
sabrina-shanman 2019-10-25 09:14:12 -07:00
parent fa51ec3daf
commit 77dcad21db

View file

@ -741,8 +741,8 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V
needsMaterialLibrary = groupMaterialName != SMART_DEFAULT_MATERIAL_NAME;
}
materials[groupMaterialName] = material;
materialNamePerShape.push_back(groupMaterialName);
}
materialNamePerShape.push_back(groupMaterialName);
hfm::Shape shape;
@ -1010,9 +1010,12 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V
// GO over the shapes once more to assign the material index correctly
for (uint32_t i = 0; i < (uint32_t)hfmModel.shapes.size(); ++i) {
auto foundMaterialIndex = materialNameToIndex.find(materialNamePerShape[i]);
if (foundMaterialIndex != materialNameToIndex.end()) {
hfmModel.shapes[i].material = foundMaterialIndex.value();
const auto& materialName = materialNamePerShape[i];
if (!materialName.isEmpty()) {
auto foundMaterialIndex = materialNameToIndex.find(materialName);
if (foundMaterialIndex != materialNameToIndex.end()) {
hfmModel.shapes[i].material = foundMaterialIndex.value();
}
}
}