From b934331985ea698f431faef2abd76e93de8b86bf Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 19 Dec 2016 20:44:00 +0100 Subject: [PATCH] closes https://github.com/assimp/assimp/issues/1111: add warning when detecting invalid mat definition. --- code/ObjFileParser.cpp | 5 ++++- test/unit/utObjImportExport.cpp | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index df9fe6be9..6980f0dab 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -568,7 +568,10 @@ void ObjFileParser::getMaterialLib() { std::string absName; // Check if directive is valid. - if(!strMatName.length()) throw DeadlyImportError("File name of the material is absent."); + if ( 0 == strMatName.length() ) { + DefaultLogger::get()->warn( "OBJ: no name for material library specified." ); + return; + } if ( m_pIO->StackSize() > 0 ) { std::string path = m_pIO->CurrentDirectory(); diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 0bfcf7cc5..4fe731b30 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -101,6 +101,20 @@ static const std::string ObjModel = "\n" "# End of file\n"; +static const std::string ObjModel_Issue1111 = + "o 1\n" + "\n" + "# Vertex list\n" + "\n" + "v -0.5 -0.5 0.5\n" + "v -0.5 -0.5 -0.5\n" + "v -0.5 0.5 -0.5\n" + "\n" + "usemtl\n" + "f 1 2 3\n" + "\n" + "# End of file\n"; + class utObjImportExport : public AbstractImportExportBase { protected: virtual void SetUp() { @@ -180,7 +194,6 @@ protected: return nullptr != scene; } - protected: Assimp::Importer *m_im; aiScene *m_expectedScene; @@ -201,3 +214,8 @@ TEST_F( utObjImportExport, obj_import_test ) { m_im->FreeScene(); } + +TEST_F( utObjImportExport, issue1111_no_mat_name_Test ) { + const aiScene *scene = m_im->ReadFileFromMemory( ( void* ) ObjModel_Issue1111.c_str(), ObjModel_Issue1111.size(), 0 ); + EXPECT_NE( nullptr, scene ); +} \ No newline at end of file