From 6641188a8edefcf52bb702a700ef56df78044f57 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 6 Dec 2015 12:18:33 +0100 Subject: [PATCH] assimp/issues/702: fix resource leak and use initializer list for all attributes of the loader instance. --- code/ColladaParser.cpp | 45 ++++++++++++++++++++++++++++------------ code/DefaultIOSystem.cpp | 1 - code/OpenGEXImporter.cpp | 13 ++++++++++++ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index b239dbe88..2ce7cad23 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -65,27 +65,46 @@ using namespace Assimp::Collada; // Constructor to be privately used by Importer ColladaParser::ColladaParser( IOSystem* pIOHandler, const std::string& pFile) : mFileName( pFile) + , mReader( NULL ) + , mDataLibrary() + , mAccessorLibrary() + , mMeshLibrary() + , mNodeLibrary() + , mImageLibrary() + , mEffectLibrary() + , mMaterialLibrary() + , mLightLibrary() + , mCameraLibrary() + , mControllerLibrary() + , mRootNode( NULL ) + , mAnims() + , mUnitSize( 1.0f ) + , mUpDirection( UP_Y ) + , mFormat(FV_1_5_n ) // We assume the newest file format by default { - mRootNode = NULL; - mUnitSize = 1.0f; - mUpDirection = UP_Y; + // Validate io-handler instance + if ( NULL == pIOHandler ) { + throw DeadlyImportError("IOSystem is NULL." ); + } - // We assume the newest file format by default - mFormat = FV_1_5_n; - - // open the file - boost::scoped_ptr file( pIOHandler->Open( pFile)); - if( file.get() == NULL) - throw DeadlyImportError( "Failed to open file " + pFile + "."); + // open the file + boost::scoped_ptr file( pIOHandler->Open( pFile ) ); + if ( file.get() == NULL ) { + throw DeadlyImportError( "Failed to open file " + pFile + "." ); + } // generate a XML reader for it - boost::scoped_ptr mIOWrapper( new CIrrXML_IOStreamReader( file.get())); + boost::scoped_ptr mIOWrapper( new CIrrXML_IOStreamReader( file.get())); mReader = irr::io::createIrrXMLReader( mIOWrapper.get()); - if( !mReader) - ThrowException( "Collada: Unable to open file."); + if (!mReader) { + ThrowException("Collada: Unable to open file."); + } // start reading ReadContents(); + + // Release file after import + pIOHandler->Close( file.get() ); } // ------------------------------------------------------------------------------------------------ diff --git a/code/DefaultIOSystem.cpp b/code/DefaultIOSystem.cpp index 89d40e2a5..83380df5b 100644 --- a/code/DefaultIOSystem.cpp +++ b/code/DefaultIOSystem.cpp @@ -176,7 +176,6 @@ std::string DefaultIOSystem::fileName( const std::string &path ) return ret; } - // ------------------------------------------------------------------------------------------------ std::string DefaultIOSystem::completeBaseName( const std::string &path ) { diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index f260cc772..ab702b717 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -801,6 +801,19 @@ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScen } } +//------------------------------------------------------------------------------------------------ +bool isSpecialRootDir(aiString &texName) { + if (texName.length < 2) { + return false; + } + + if (texName.data[0] = '/' || texName.data[1] == '/') { + return true; + } + + return false; +} + //------------------------------------------------------------------------------------------------ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) { if( NULL == node ) {