From 54be5fdb7b81917e5e624538b6a01a308ed06b02 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 3 Dec 2018 22:03:50 +0100 Subject: [PATCH 1/5] Update XFileParser.cpp --- code/XFileParser.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/code/XFileParser.cpp b/code/XFileParser.cpp index e7bf8518c..95875116f 100644 --- a/code/XFileParser.cpp +++ b/code/XFileParser.cpp @@ -583,22 +583,31 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh) pMesh->mNormals.resize( numNormals); // read normal vectors - for( unsigned int a = 0; a < numNormals; a++) + for( unsigned int a = 0; a < numNormals; ++a) { pMesh->mNormals[a] = ReadVector3(); + } // read normal indices unsigned int numFaces = ReadInt(); - if( numFaces != pMesh->mPosFaces.size()) + if( numFaces != pMesh->mPosFaces.size()) { 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(); - pMesh->mNormFaces.push_back( Face()); + pMesh->mNormFaces.push_back( Face() ); 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()); + } TestForSeparator(); } From b1da322debc6fe1bb549f3d716e8d5787c0e89f8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 3 Dec 2018 23:13:10 +0100 Subject: [PATCH 2/5] Update XFileParser.cpp Add misisng bracket. --- code/XFileParser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/XFileParser.cpp b/code/XFileParser.cpp index 95875116f..0adddd957 100644 --- a/code/XFileParser.cpp +++ b/code/XFileParser.cpp @@ -598,6 +598,7 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh) TestForSeparator(); CheckForClosingBrace(); return; + } // normal face creation pMesh->mNormFaces.resize( pMesh->mNormFaces.size() + numFaces ); From a4bda3a205ddb75728016b3dd7eaa525a135d200 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 9 Jun 2019 21:25:25 +0200 Subject: [PATCH 3/5] Update XFileParser.cpp Test --- code/XFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/XFileParser.cpp b/code/XFileParser.cpp index d0998e9c8..caccc7fad 100644 --- a/code/XFileParser.cpp +++ b/code/XFileParser.cpp @@ -595,7 +595,7 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh) // do not crah when no face definitions are there if (numFaces == 0) { - TestForSeparator(); + //TestForSeparator(); CheckForClosingBrace(); return; } From 7e20356a203b2c0a15aec2c479a6edecf286a0d3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 10 Jun 2019 20:32:56 +0200 Subject: [PATCH 4/5] Update XFileParser.cpp Fix exception. --- code/XFileParser.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/code/XFileParser.cpp b/code/XFileParser.cpp index caccc7fad..08d3c88da 100644 --- a/code/XFileParser.cpp +++ b/code/XFileParser.cpp @@ -594,23 +594,19 @@ void XFileParser::ParseDataObjectMeshNormals( Mesh* pMesh) } // do not crah when no face definitions are there - if (numFaces == 0) { - //TestForSeparator(); - CheckForClosingBrace(); - return; - } + if (numFaces > 0) { + // normal face creation + pMesh->mNormFaces.resize( pMesh->mNormFaces.size() + numFaces ); + for( unsigned int a = 0; a < numFaces; ++a ) { + unsigned int numIndices = ReadInt(); + pMesh->mNormFaces.push_back( Face() ); + Face& face = pMesh->mNormFaces.back(); + for( unsigned int b = 0; b < numIndices; ++b ) { + face.mIndices.push_back( ReadInt()); + } - // normal face creation - pMesh->mNormFaces.resize( pMesh->mNormFaces.size() + numFaces ); - for( unsigned int a = 0; a < numFaces; ++a ) { - unsigned int numIndices = ReadInt(); - pMesh->mNormFaces.push_back( Face() ); - Face& face = pMesh->mNormFaces.back(); - for( unsigned int b = 0; b < numIndices; ++b ) { - face.mIndices.push_back( ReadInt()); + TestForSeparator(); } - - TestForSeparator(); } CheckForClosingBrace(); From ced080f9f388061f5889f0ee4d74d3844aff06bd Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 15 Jun 2019 19:17:15 +0200 Subject: [PATCH 5/5] X: fix out of bound access. --- code/X/XFileImporter.cpp | 7 +++++-- code/X/XFileImporter.h | 6 +++--- test/models/PLY/cube_test.ply | 2 +- test/unit/utBlendImportMaterials.cpp | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/code/X/XFileImporter.cpp b/code/X/XFileImporter.cpp index 10547bb8a..be7256d5c 100644 --- a/code/X/XFileImporter.cpp +++ b/code/X/XFileImporter.cpp @@ -332,7 +332,7 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec // collect vertex data for indices of this face for( unsigned int d = 0; d < df.mNumIndices; ++d ) { - df.mIndices[d] = newIndex; + df.mIndices[ d ] = newIndex; const unsigned int newIdx( pf.mIndices[ d ] ); if ( newIdx > sourceMesh->mPositions.size() ) { continue; @@ -344,7 +344,10 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec mesh->mVertices[newIndex] = sourceMesh->mPositions[pf.mIndices[d]]; // Normal, if present if ( mesh->HasNormals() ) { - mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ sourceMesh->mNormFaces[ f ].mIndices[ d ] ]; + if ( sourceMesh->mNormFaces[ f ].mIndices.size() > d ) { + const size_t idx( sourceMesh->mNormFaces[ f ].mIndices[ d ] ); + mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ idx ]; + } } // texture coord sets diff --git a/code/X/XFileImporter.h b/code/X/XFileImporter.h index d1b8d3f47..7d12b6fdf 100644 --- a/code/X/XFileImporter.h +++ b/code/X/XFileImporter.h @@ -58,13 +58,13 @@ struct aiNode; namespace Assimp { namespace XFile { -struct Scene; -struct Node; + struct Scene; + struct Node; } // --------------------------------------------------------------------------- /** The XFileImporter is a worker class capable of importing a scene from a - * DirectX file .x + * DirectX file .x */ class XFileImporter : public BaseImporter { public: diff --git a/test/models/PLY/cube_test.ply b/test/models/PLY/cube_test.ply index bb0839286..194798cf0 100644 --- a/test/models/PLY/cube_test.ply +++ b/test/models/PLY/cube_test.ply @@ -1,6 +1,6 @@ ply format ascii 1.0 -comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.2760932948) +comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.3945266037) element vertex 8 property float x property float y diff --git a/test/unit/utBlendImportMaterials.cpp b/test/unit/utBlendImportMaterials.cpp index cefacbe27..151c614c0 100644 --- a/test/unit/utBlendImportMaterials.cpp +++ b/test/unit/utBlendImportMaterials.cpp @@ -133,10 +133,10 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings // material has 2 diffuse textures ASSERT_TRUE(pTest->HasMaterials()); - EXPECT_EQ(1, pTest->mNumMaterials); + EXPECT_EQ(1u, pTest->mNumMaterials); const aiMaterial *pMat = pTest->mMaterials[0]; ASSERT_TRUE(nullptr != pMat); - ASSERT_EQ(2, pMat->GetTextureCount(aiTextureType_DIFFUSE)); + ASSERT_EQ(2u, pMat->GetTextureCount(aiTextureType_DIFFUSE)); aiString aPath; aiTextureMapping tm = aiTextureMapping::aiTextureMapping_OTHER; aiReturn result = pMat->GetTexture(aiTextureType_DIFFUSE, 0, &aPath, &tm); @@ -146,7 +146,7 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings // mesh has 2 texturecoord sets ASSERT_TRUE(pTest->HasMeshes()); - EXPECT_EQ(1, pTest->mNumMeshes); + EXPECT_EQ(1u, pTest->mNumMeshes); const aiMesh *pMesh = pTest->mMeshes[0]; ASSERT_TRUE(nullptr != pMesh); ASSERT_TRUE(pMesh->HasTextureCoords(0));