From c1c4a5ed2a689dbd6b870682e9db51013a7cc7f8 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 29 Oct 2017 15:12:56 +0100 Subject: [PATCH 1/3] Add two unit tests for OBJ importer --- test/unit/utObjImportExport.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 3b08df80f..800b68b22 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -305,3 +305,38 @@ TEST_F(utObjImportExport, relative_indices_Test) { } } + +TEST_F(utObjImportExport, homogeneous_coordinates_Test) { + static const std::string ObjModel = + "v -0.500000 0.000000 0.400000 0.50000\n" + "v -0.500000 0.000000 -0.800000 1.00000\n" + "v 0.500000 1.000000 -0.800000 0.5000\n" + "f 1 2 3\nB"; + + Assimp::Importer myimporter; + const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); + EXPECT_NE(nullptr, scene); + + EXPECT_EQ(scene->mNumMeshes, 1); + const aiMesh *mesh = scene->mMeshes[0]; + EXPECT_EQ(mesh->mNumVertices, 3); + EXPECT_EQ(mesh->mNumFaces, 1); + const aiFace face = mesh->mFaces[0]; + EXPECT_EQ(face.mNumIndices, 3); + const aiVector3D vertice = mesh->mVertices[0]; + EXPECT_EQ(vertice.x, -1.0f); + EXPECT_EQ(vertice.y, 0.0f); + EXPECT_EQ(vertice.z, 0.8f); +} + +TEST_F(utObjImportExport, 0based_array_Test) { + static const std::string ObjModel = + "v -0.500000 0.000000 0.400000\n" + "v -0.500000 0.000000 -0.800000\n" + "v -0.500000 1.000000 -0.800000\n" + "f 0 1 2\nB"; + + Assimp::Importer myimporter; + const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), 0); + EXPECT_EQ(nullptr, scene); +} From c9ada44ab54c63627ba9fa0a50dbb4a16dc827fc Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 4 Nov 2017 17:05:23 +0100 Subject: [PATCH 2/3] Fix memory leak in case of an error. --- code/ObjFileParser.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 4b203a8c2..0435f9b88 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -477,6 +477,8 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } } else { //On error, std::atoi will return 0 which is not a valid value + delete m_pModel; + m_pModel = nullptr; throw DeadlyImportError("OBJ: Invalid face indice"); } From a33e115fd1dacc9251fc5ae6fde2a94e11b678dd Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 4 Nov 2017 18:26:30 +0100 Subject: [PATCH 3/3] fix mem-lead: face will be not released in case of an error. --- code/ObjFileParser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 0435f9b88..d89d52977 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -477,6 +477,7 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } } else { //On error, std::atoi will return 0 which is not a valid value + delete face; delete m_pModel; m_pModel = nullptr; throw DeadlyImportError("OBJ: Invalid face indice");