assimp/issues/702: fix resource leak and use initializer list for all

attributes of the loader instance.
pull/703/head^2
Kim Kulling 2015-12-06 12:18:33 +01:00
parent 8736907009
commit 6641188a8e
3 changed files with 45 additions and 14 deletions

View File

@ -65,27 +65,46 @@ using namespace Assimp::Collada;
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
ColladaParser::ColladaParser( IOSystem* pIOHandler, const std::string& pFile) ColladaParser::ColladaParser( IOSystem* pIOHandler, const std::string& pFile)
: mFileName( 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; // Validate io-handler instance
mUnitSize = 1.0f; if ( NULL == pIOHandler ) {
mUpDirection = UP_Y; throw DeadlyImportError("IOSystem is NULL." );
}
// We assume the newest file format by default // open the file
mFormat = FV_1_5_n; boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile ) );
if ( file.get() == NULL ) {
// open the file throw DeadlyImportError( "Failed to open file " + pFile + "." );
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); }
if( file.get() == NULL)
throw DeadlyImportError( "Failed to open file " + pFile + ".");
// generate a XML reader for it // generate a XML reader for it
boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper( new CIrrXML_IOStreamReader( file.get())); boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper( new CIrrXML_IOStreamReader( file.get()));
mReader = irr::io::createIrrXMLReader( mIOWrapper.get()); mReader = irr::io::createIrrXMLReader( mIOWrapper.get());
if( !mReader) if (!mReader) {
ThrowException( "Collada: Unable to open file."); ThrowException("Collada: Unable to open file.");
}
// start reading // start reading
ReadContents(); ReadContents();
// Release file after import
pIOHandler->Close( file.get() );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -176,7 +176,6 @@ std::string DefaultIOSystem::fileName( const std::string &path )
return ret; return ret;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::string DefaultIOSystem::completeBaseName( const std::string &path ) std::string DefaultIOSystem::completeBaseName( const std::string &path )
{ {

View File

@ -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 ) { void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == node ) { if( NULL == node ) {