From 6c0553d810b2050e6291c8e0115c18f915ffa29b Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 19 May 2018 22:02:54 +0200 Subject: [PATCH 1/3] Add mesh name to ValidateDataStructure log --- code/ValidateDataStructure.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index 51e04b96b..ed6bde724 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -369,7 +369,7 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh) // positions must always be there ... if (!pMesh->mNumVertices || (!pMesh->mVertices && !mScene->mFlags)) { - ReportError("The mesh contains no vertices"); + ReportError("The mesh %s contains no vertices", pMesh->mName.C_Str()); } if (pMesh->mNumVertices > AI_MAX_VERTICES) { @@ -386,7 +386,7 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh) // faces, too if (!pMesh->mNumFaces || (!pMesh->mFaces && !mScene->mFlags)) { - ReportError("Mesh contains no faces"); + ReportError("Mesh %s contains no faces", pMesh->mName.C_Str()); } // now check whether the face indexing layout is correct: From 4b5c49b0872e76eb1bd41af63bb3081236c5bb9f Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 19 May 2018 22:03:59 +0200 Subject: [PATCH 2/3] Add test for issue 1970: STL with empty solid --- test/models/STL/triangle_with_empty_solid.stl | 11 +++++++++++ test/unit/utSTLImportExport.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/models/STL/triangle_with_empty_solid.stl diff --git a/test/models/STL/triangle_with_empty_solid.stl b/test/models/STL/triangle_with_empty_solid.stl new file mode 100644 index 000000000..2364b792f --- /dev/null +++ b/test/models/STL/triangle_with_empty_solid.stl @@ -0,0 +1,11 @@ +solid testTriangle + facet normal 0.0 0.0 1.0 + outer loop + vertex 1.0 1.0 0.0 + vertex -1.0 1.0 0.0 + vertex 0.0 -1.0 0.0 + endloop + endfacet +endsolid +solid emptySolid +endsolid diff --git a/test/unit/utSTLImportExport.cpp b/test/unit/utSTLImportExport.cpp index 181862560..de1e78a26 100644 --- a/test/unit/utSTLImportExport.cpp +++ b/test/unit/utSTLImportExport.cpp @@ -73,6 +73,16 @@ TEST_F( utSTLImporterExporter, test_with_two_solids ) { EXPECT_NE( nullptr, scene ); } +TEST_F(utSTLImporterExporter, test_with_empty_solid) { + Assimp::Importer importer; + //STL File with empty mesh. We should still be able to import other meshes in this file. ValidateDataStructure should fail. + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/STL/triangle_with_empty_solid.stl", 0); + EXPECT_NE(nullptr, scene); + + const aiScene *scene2 = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/STL/triangle_with_empty_solid.stl", aiProcess_ValidateDataStructure); + EXPECT_EQ(nullptr, scene2); +} + #ifndef ASSIMP_BUILD_NO_EXPORT TEST_F(utSTLImporterExporter, exporterTest) { From 84739fda0abd018a673b948b78999b4a6df0b92d Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sat, 19 May 2018 22:05:06 +0200 Subject: [PATCH 3/3] Fix #1970: stl with empty solid Log warning instead of stopping whole import. --- code/STLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 46808503d..73a780e34 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -352,7 +352,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) { if (positionBuffer.empty()) { pMesh->mNumFaces = 0; - throw DeadlyImportError("STL: ASCII file is empty or invalid; no data loaded"); + ASSIMP_LOG_WARN("STL: mesh is empty or invalid; no data loaded"); } if (positionBuffer.size() % 3 != 0) { pMesh->mNumFaces = 0;