From c3d8464a371112ac7deaa755cdd3d5fe13fc00f5 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 10 Sep 2018 16:41:12 +0300 Subject: [PATCH 1/2] Remove aiCreateAndRegisterDefaultMaterial, it's completely wrong --- code/Assimp.cpp | 2 -- code/Importer.cpp | 2 -- code/MaterialSystem.cpp | 20 -------------------- code/STLLoader.cpp | 5 ++--- include/assimp/material.h | 20 -------------------- test/unit/utMaterialSystem.cpp | 10 +--------- 6 files changed, 3 insertions(+), 56 deletions(-) diff --git a/code/Assimp.cpp b/code/Assimp.cpp index 2a9b896e7..b682d257b 100644 --- a/code/Assimp.cpp +++ b/code/Assimp.cpp @@ -272,8 +272,6 @@ void aiReleaseImport( const aiScene* pScene) ASSIMP_BEGIN_EXCEPTION_REGION(); - aiReleaseDefaultMaterial(); - // find the importer associated with this data const ScenePrivateData* priv = ScenePriv(pScene); if( !priv || !priv->mOrigImporter) { diff --git a/code/Importer.cpp b/code/Importer.cpp index 7aabe0a5f..32bec9414 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -178,7 +178,6 @@ Importer::~Importer() { // Delete all import plugins DeleteImporterInstanceList(pimpl->mImporter); - aiReleaseDefaultMaterial(); // Delete all post-processing plug-ins for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) @@ -385,7 +384,6 @@ void Importer::FreeScene( ) { ASSIMP_BEGIN_EXCEPTION_REGION(); - aiReleaseDefaultMaterial(); delete pimpl->mScene; pimpl->mScene = NULL; diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index 3679c93c7..fa8fb819c 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -387,26 +387,6 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat, return AI_SUCCESS; } -static aiMaterial *DefaultMaterial = nullptr; - -// ------------------------------------------------------------------------------------------------ -// Will return the default material. -aiMaterial *aiCreateAndRegisterDefaultMaterial() { - if (nullptr == DefaultMaterial) { - DefaultMaterial = new aiMaterial; - aiString s; - s.Set(AI_DEFAULT_MATERIAL_NAME); - DefaultMaterial->AddProperty(&s, AI_MATKEY_NAME); - } - - return DefaultMaterial; -} - -// ------------------------------------------------------------------------------------------------ -// Will return the default material. -void aiReleaseDefaultMaterial() { - DefaultMaterial = nullptr; -} static const unsigned int DefaultNumAllocated = 5; diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 3f8c810fa..fb866bb7a 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -214,11 +214,10 @@ void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS // create a single default material, using a white diffuse color for consistency with // other geometric types (e.g., PLY). - aiMaterial* pcMat = aiCreateAndRegisterDefaultMaterial(); - /*aiMaterial* pcMat = new aiMaterial(); + aiMaterial* pcMat = new aiMaterial(); aiString s; s.Set(AI_DEFAULT_MATERIAL_NAME); - pcMat->AddProperty(&s, AI_MATKEY_NAME);*/ + pcMat->AddProperty(&s, AI_MATKEY_NAME); aiColor4D clrDiffuse(ai_real(1.0),ai_real(1.0),ai_real(1.0),ai_real(1.0)); if (bMatClr) { diff --git a/include/assimp/material.h b/include/assimp/material.h index 6564e047b..911853b4b 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -1565,26 +1565,6 @@ C_ENUM aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat, unsigned int* flags /*= NULL*/); #endif // !#ifdef __cplusplus -// --------------------------------------------------------------------------- -/** @brief Helper function to get all values pertaining to a particular -* texture slot from a material structure. -* -* @return Pointer showing to the default material. -*/ -// --------------------------------------------------------------------------- -#ifdef __cplusplus -ASSIMP_API aiMaterial *aiCreateAndRegisterDefaultMaterial(void); -#else -C_STRUCT aiMaterial *aiCreateAndRegisterDefaultMaterial(void); -#endif // !#ifdef __cplusplus - -// --------------------------------------------------------------------------- -/** - * @brief Helper function to release the default material instance, the - * instance will not be destroyed. - */ -// --------------------------------------------------------------------------- -ASSIMP_API void aiReleaseDefaultMaterial(); #ifdef __cplusplus } diff --git a/test/unit/utMaterialSystem.cpp b/test/unit/utMaterialSystem.cpp index 550dc63da..55ee6e2a0 100644 --- a/test/unit/utMaterialSystem.cpp +++ b/test/unit/utMaterialSystem.cpp @@ -129,18 +129,10 @@ TEST_F(MaterialSystemTest, testStringProperty) { EXPECT_STREQ("Hello, this is a small test", s.data); } -// ------------------------------------------------------------------------------------------------ -TEST_F(MaterialSystemTest, testDefaultMaterialAccess) { - aiMaterial *mat = aiCreateAndRegisterDefaultMaterial(); - EXPECT_NE(nullptr, mat); - aiReleaseDefaultMaterial(); - - delete mat; -} // ------------------------------------------------------------------------------------------------ TEST_F(MaterialSystemTest, testMaterialNameAccess) { - aiMaterial *mat = aiCreateAndRegisterDefaultMaterial(); + aiMaterial *mat = new aiMaterial(); EXPECT_NE(nullptr, mat); aiString name = mat->GetName(); From 4ff52c98bb6a4a687fb5f5b38c445d7e757ebb60 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 10 Sep 2018 16:43:27 +0300 Subject: [PATCH 2/2] Add unit test for two independent importers loading STL models --- test/unit/utSTLImportExport.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/utSTLImportExport.cpp b/test/unit/utSTLImportExport.cpp index 9ebfb0f05..ee62253fd 100644 --- a/test/unit/utSTLImportExport.cpp +++ b/test/unit/utSTLImportExport.cpp @@ -67,6 +67,20 @@ TEST_F( utSTLImporterExporter, importSTLFromFileTest ) { EXPECT_TRUE( importerTest() ); } + +TEST_F(utSTLImporterExporter, test_multiple) { + // import same file twice, each with its own importer + // must work both times and not crash + Assimp::Importer importer1; + const aiScene *scene1 = importer1.ReadFile( ASSIMP_TEST_MODELS_DIR "/STL/Spider_ascii.stl", aiProcess_ValidateDataStructure ); + EXPECT_NE(nullptr, scene1); + + Assimp::Importer importer2; + const aiScene *scene2 = importer2.ReadFile( ASSIMP_TEST_MODELS_DIR "/STL/Spider_ascii.stl", aiProcess_ValidateDataStructure ); + EXPECT_NE(nullptr, scene2); +} + + TEST_F( utSTLImporterExporter, test_with_two_solids ) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/STL/triangle_with_two_solids.stl", aiProcess_ValidateDataStructure );