From 42202c22043923946b87481ff01669d4bf633fc4 Mon Sep 17 00:00:00 2001 From: Vitaly Ovchinnikov Date: Fri, 26 Apr 2019 22:13:29 +1200 Subject: [PATCH] a test for bad OBJ file format and code fix that handles it --- code/ObjFileParser.cpp | 10 +++------- test/unit/utObjImportExport.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index a8509b583..17c83ee8f 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -429,13 +429,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { if (type == aiPrimitiveType_POINT) { ASSIMP_LOG_ERROR("Obj: Separator unexpected in point statement"); } - if (iPos == 0) { - //if there are no texture coordinates in the file, but normals - if (!vt && vn) { - iPos = 1; - iStep++; - } - } iPos++; } else if( IsSpaceOrNewLine( *m_DataIt ) ) { iPos = 0; @@ -452,6 +445,9 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { ++iStep; } + if (iPos == 1 && !vt && vn) + iPos = 2; // skip texture coords for normals if there are no tex coords + if ( iVal > 0 ) { // Store parsed index if ( 0 == iPos ) { diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 2d1933094..bb0d36b13 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -391,6 +391,39 @@ TEST_F(utObjImportExport, invalid_normals_uvs) { EXPECT_NE(nullptr, scene); } +TEST_F(utObjImportExport, no_vt_just_vns) { + static const char *ObjModel = + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 0 0 0\n" + "v 10 0 0\n" + "v 0 10 0\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "vn 0 0 1\n" + "f 10/10 11/11 12/12\n"; + + Assimp::Importer myImporter; + const aiScene *scene = myImporter.ReadFileFromMemory(ObjModel, strlen(ObjModel), 0); + EXPECT_NE(nullptr, scene); +} + TEST_F( utObjImportExport, mtllib_after_g ) { ::Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OBJ/cube_mtllib_after_g.obj", aiProcess_ValidateDataStructure );