Explorar el Código

Update XFileParser.cpp

Kim Kulling hace 6 años
padre
commit
54be5fdb7b
Se han modificado 1 ficheros con 16 adiciones y 7 borrados
  1. 16 7
      code/XFileParser.cpp

+ 16 - 7
code/XFileParser.cpp

@@ -583,22 +583,31 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh)
     pMesh->mNormals.resize( numNormals);
     pMesh->mNormals.resize( numNormals);
 
 
     // read normal vectors
     // read normal vectors
-    for( unsigned int a = 0; a < numNormals; a++)
+    for( unsigned int a = 0; a < numNormals; ++a) {
         pMesh->mNormals[a] = ReadVector3();
         pMesh->mNormals[a] = ReadVector3();
+    }
 
 
     // read normal indices
     // read normal indices
     unsigned int numFaces = ReadInt();
     unsigned int numFaces = ReadInt();
-    if( numFaces != pMesh->mPosFaces.size())
+    if( numFaces != pMesh->mPosFaces.size()) {
         ThrowException( "Normal face count does not match vertex face count.");
         ThrowException( "Normal face count does not match vertex face count.");
+    }
 
 
-    for( unsigned int a = 0; a < numFaces; a++)
-    {
+    // do not crah when no face definitions are there
+    if (numFaces == 0) {
+        TestForSeparator();
+        CheckForClosingBrace();
+        return;
+
+    // normal face creation
+    pMesh->mNormFaces.resize( pMesh->mNormFaces.size() + numFaces );
+    for( unsigned int a = 0; a < numFaces; ++a ) {
         unsigned int numIndices = ReadInt();
         unsigned int numIndices = ReadInt();
-        pMesh->mNormFaces.push_back( Face());
+        pMesh->mNormFaces.push_back( Face() );
         Face& face = pMesh->mNormFaces.back();
         Face& face = pMesh->mNormFaces.back();
-
-        for( unsigned int b = 0; b < numIndices; b++)
+        for( unsigned int b = 0; b < numIndices; ++b ) {
             face.mIndices.push_back( ReadInt());
             face.mIndices.push_back( ReadInt());
+        }
 
 
         TestForSeparator();
         TestForSeparator();
     }
     }