From db3f232fc9f75e416862afb00bd1d3f7c5936670 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Tue, 24 Oct 2017 20:54:59 -0700 Subject: [PATCH] Cope with geometry opting out of geometry. Some FBX files have index arrays that contain -1 (indeed, that are nothing but negative ones). Presumably the intention is to specify "no material". In any case, let's not segfault. --- src/Fbx2Raw.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index 4f736f3..d293c4e 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -265,6 +265,9 @@ public: for (int ii = 0; ii < indices->GetCount(); ii++) { int materialNum = indices->GetAt(ii); + if (materialNum < 0) { + continue; + } if (materialNum >= summaries.size()) { summaries.resize(materialNum + 1); } @@ -280,9 +283,11 @@ public: const std::shared_ptr GetMaterial(const int polygonIndex) const { if (mappingMode != FbxGeometryElement::eNone) { - const auto materialNum = static_cast(indices->GetAt( - (mappingMode == FbxGeometryElement::eByPolygon) ? polygonIndex : 0)); - return summaries.at(materialNum); + const int materialNum = indices->GetAt((mappingMode == FbxGeometryElement::eByPolygon) ? polygonIndex : 0); + if (materialNum < 0) { + return nullptr; + } + return summaries.at((unsigned long) materialNum); } return nullptr; }