Revamp exception handling. ImportErrorException renamed to DeadlyImportError to avoid silent regressions. Exceptions now thrown by value, and caught by reference. Put guards in all C++ and C API functions to avoid unwanted exception propagation across module and language boundaries.

PLEASE TEST CAREFULLY IF THIS SHOULD CAUSE REGRESSIONS.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@617 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-03-18 17:00:12 +00:00
parent 79c14ce896
commit 762a7df46a
61 changed files with 565 additions and 354 deletions

View File

@ -425,7 +425,7 @@ void Discreet3DSImporter::ConvertMeshes(aiScene* pcOut)
// We should have at least one face here // We should have at least one face here
if (!iFaceCnt) if (!iFaceCnt)
throw new ImportErrorException("No faces loaded. The mesh is empty"); throw DeadlyImportError("No faces loaded. The mesh is empty");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -132,7 +132,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
// We should have at least one chunk // We should have at least one chunk
if (stream.GetRemainingSize() < 16) { if (stream.GetRemainingSize() < 16) {
throw new ImportErrorException("3DS file is either empty or corrupt: " + pFile); throw DeadlyImportError("3DS file is either empty or corrupt: " + pFile);
} }
// Allocate our temporary 3DS representation // Allocate our temporary 3DS representation
@ -220,7 +220,7 @@ void Discreet3DSImporter::ReadChunk(Discreet3DS::Chunk* pcOut)
pcOut->Size = stream->GetI4(); pcOut->Size = stream->GetI4();
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSize()) if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSize())
throw new ImportErrorException("Chunk is too large"); throw DeadlyImportError("Chunk is too large");
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSizeToLimit()) if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSizeToLimit())
DefaultLogger::get()->error("3DS: Chunk overflow"); DefaultLogger::get()->error("3DS: Chunk overflow");

View File

@ -741,7 +741,7 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open AC3D file " + pFile + "."); throw DeadlyImportError( "Failed to open AC3D file " + pFile + ".");
// allocate storage and copy the contents of the file to a memory buffer // allocate storage and copy the contents of the file to a memory buffer
std::vector<char> mBuffer2; std::vector<char> mBuffer2;
@ -753,7 +753,7 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
lights = polys = worlds = groups = 0; lights = polys = worlds = groups = 0;
if (::strncmp(buffer,"AC3D",4)) { if (::strncmp(buffer,"AC3D",4)) {
throw new ImportErrorException("AC3D: No valid AC3D file, magic sequence not found"); throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found");
} }
// print the file format version to the console // print the file format version to the console
@ -800,7 +800,7 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
if (rootObjects.empty() || !mNumMeshes) if (rootObjects.empty() || !mNumMeshes)
{ {
throw new ImportErrorException("AC3D: No meshes have been loaded"); throw DeadlyImportError("AC3D: No meshes have been loaded");
} }
if (materials.empty()) if (materials.empty())
{ {
@ -834,7 +834,7 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
// copy meshes // copy meshes
if (meshes.empty()) if (meshes.empty())
{ {
throw new ImportErrorException("An unknown error occured during converting"); throw DeadlyImportError("An unknown error occured during converting");
} }
pScene->mNumMeshes = (unsigned int)meshes.size(); pScene->mNumMeshes = (unsigned int)meshes.size();
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];

View File

@ -110,7 +110,7 @@ void ASEImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open ASE file " + pFile + "."); throw DeadlyImportError( "Failed to open ASE file " + pFile + ".");
} }
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
@ -703,7 +703,7 @@ void ASEImporter::BuildNodes() {
// The root node should not have at least one child or the file is valid // The root node should not have at least one child or the file is valid
if (!pcScene->mRootNode->mNumChildren) { if (!pcScene->mRootNode->mNumChildren) {
throw new ImportErrorException("ASE: No nodes loaded. The file is either empty or corrupt"); throw DeadlyImportError("ASE: No nodes loaded. The file is either empty or corrupt");
} }
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system

View File

@ -179,7 +179,7 @@ void Parser::LogError(const char* szWarn)
#endif #endif
// throw an exception // throw an exception
throw new ImportErrorException(szTemp); throw DeadlyImportError(szTemp);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -267,6 +267,10 @@ const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
aiFileIO* pFS) aiFileIO* pFS)
{ {
ai_assert(NULL != pFile); ai_assert(NULL != pFile);
const aiScene* scene = NULL;
ASSIMP_BEGIN_EXCEPTION_REGION();
// create an Importer for this file // create an Importer for this file
Assimp::Importer* imp = new Assimp::Importer(); Assimp::Importer* imp = new Assimp::Importer();
@ -288,7 +292,7 @@ const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
} }
// and have it read the file // and have it read the file
const aiScene* scene = imp->ReadFile( pFile, pFlags); scene = imp->ReadFile( pFile, pFlags);
// if succeeded, place it in the collection of active processes // if succeeded, place it in the collection of active processes
if( scene) { if( scene) {
@ -304,6 +308,7 @@ const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
} }
// return imported data. If the import failed the pointer is NULL anyways // return imported data. If the import failed the pointer is NULL anyways
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return scene; return scene;
} }
@ -316,6 +321,9 @@ const aiScene* aiImportFileFromMemory(
{ {
ai_assert(NULL != pBuffer && 0 != pLength); ai_assert(NULL != pBuffer && 0 != pLength);
const aiScene* scene = NULL;
ASSIMP_BEGIN_EXCEPTION_REGION();
// create an Importer for this file // create an Importer for this file
Assimp::Importer* imp = new Assimp::Importer(); Assimp::Importer* imp = new Assimp::Importer();
@ -332,7 +340,7 @@ const aiScene* aiImportFileFromMemory(
#endif #endif
// and have it read the file from the memory buffer // and have it read the file from the memory buffer
const aiScene* scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint); scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
// if succeeded, place it in the collection of active processes // if succeeded, place it in the collection of active processes
if( scene) { if( scene) {
@ -347,6 +355,7 @@ const aiScene* aiImportFileFromMemory(
delete imp; delete imp;
} }
// return imported data. If the import failed the pointer is NULL anyways // return imported data. If the import failed the pointer is NULL anyways
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return scene; return scene;
} }
@ -358,6 +367,8 @@ void aiReleaseImport( const aiScene* pScene)
return; return;
} }
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
@ -373,12 +384,18 @@ void aiReleaseImport( const aiScene* pScene)
// kill the importer, the data dies with it // kill the importer, the data dies with it
delete it->second; delete it->second;
gActiveImports.erase( it); gActiveImports.erase( it);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene, ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
unsigned int pFlags) unsigned int pFlags)
{ {
const aiScene* sc = NULL;
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
@ -392,7 +409,7 @@ ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
lock.unlock(); lock.unlock();
#endif #endif
const aiScene* sc = it->second->ApplyPostProcessing(pFlags); sc = it->second->ApplyPostProcessing(pFlags);
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
lock.lock(); lock.lock();
#endif #endif
@ -403,7 +420,8 @@ ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
return NULL; return NULL;
} }
return it->first; ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return sc;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -419,6 +437,8 @@ void CallbackToLogRedirector (const char* msg, char* dt)
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file) ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
{ {
aiLogStream sout; aiLogStream sout;
ASSIMP_BEGIN_EXCEPTION_REGION();
LogStream* stream = LogStream::createDefaultStream(pStream,file); LogStream* stream = LogStream::createDefaultStream(pStream,file);
if (!stream) { if (!stream) {
sout.callback = NULL; sout.callback = NULL;
@ -429,15 +449,19 @@ ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const
sout.user = (char*)stream; sout.user = (char*)stream;
} }
gPredefinedStreams.push_back(stream); gPredefinedStreams.push_back(stream);
ASSIMP_END_EXCEPTION_REGION(aiLogStream);
return sout; return sout;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API void aiAttachLogStream( const aiLogStream* stream ) ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gLogStreamMutex); boost::mutex::scoped_lock lock(gLogStreamMutex);
#endif #endif
LogStream* lg = new LogToCallbackRedirector(*stream); LogStream* lg = new LogToCallbackRedirector(*stream);
gActiveLogStreams[*stream] = lg; gActiveLogStreams[*stream] = lg;
@ -445,11 +469,14 @@ ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL)); DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
} }
DefaultLogger::get()->attachStream(lg); DefaultLogger::get()->attachStream(lg);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream) ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gLogStreamMutex); boost::mutex::scoped_lock lock(gLogStreamMutex);
#endif #endif
@ -465,12 +492,14 @@ ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
if (gActiveLogStreams.empty()) { if (gActiveLogStreams.empty()) {
DefaultLogger::kill(); DefaultLogger::kill();
} }
ASSIMP_END_EXCEPTION_REGION(aiReturn);
return AI_SUCCESS; return AI_SUCCESS;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API void aiDetachAllLogStreams(void) ASSIMP_API void aiDetachAllLogStreams(void)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gLogStreamMutex); boost::mutex::scoped_lock lock(gLogStreamMutex);
#endif #endif
@ -479,6 +508,7 @@ ASSIMP_API void aiDetachAllLogStreams(void)
} }
gActiveLogStreams.clear(); gActiveLogStreams.clear();
DefaultLogger::kill(); DefaultLogger::kill();
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -502,6 +532,9 @@ const char* aiGetErrorString()
aiBool aiIsExtensionSupported(const char* szExtension) aiBool aiIsExtensionSupported(const char* szExtension)
{ {
ai_assert(NULL != szExtension); ai_assert(NULL != szExtension);
aiBool candoit=AI_FALSE;
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
@ -512,7 +545,10 @@ aiBool aiIsExtensionSupported(const char* szExtension)
// fixme: no need to create a temporary Importer instance just for that .. // fixme: no need to create a temporary Importer instance just for that ..
Assimp::Importer tmp; Assimp::Importer tmp;
return tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE; candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
ASSIMP_END_EXCEPTION_REGION(aiBool);
return candoit;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -520,6 +556,8 @@ aiBool aiIsExtensionSupported(const char* szExtension)
void aiGetExtensionList(aiString* szOut) void aiGetExtensionList(aiString* szOut)
{ {
ai_assert(NULL != szOut); ai_assert(NULL != szOut);
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
@ -531,6 +569,8 @@ void aiGetExtensionList(aiString* szOut)
// fixme: no need to create a temporary Importer instance just for that .. // fixme: no need to create a temporary Importer instance just for that ..
Assimp::Importer tmp; Assimp::Importer tmp;
tmp.GetExtensionList(*szOut); tmp.GetExtensionList(*szOut);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -538,6 +578,7 @@ void aiGetExtensionList(aiString* szOut)
void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn, void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
C_STRUCT aiMemoryInfo* in) C_STRUCT aiMemoryInfo* in)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
@ -554,26 +595,31 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
lock.unlock(); lock.unlock();
#endif #endif
it->second->GetMemoryRequirements(*in); it->second->GetMemoryRequirements(*in);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Importer::SetPropertyInteger // Importer::SetPropertyInteger
ASSIMP_API void aiSetImportPropertyInteger(const char* szName, int value) ASSIMP_API void aiSetImportPropertyInteger(const char* szName, int value)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
SetGenericProperty<int>(gIntProperties,szName,value,NULL); SetGenericProperty<int>(gIntProperties,szName,value,NULL);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Importer::SetPropertyFloat // Importer::SetPropertyFloat
ASSIMP_API void aiSetImportPropertyFloat(const char* szName, float value) ASSIMP_API void aiSetImportPropertyFloat(const char* szName, float value)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
SetGenericProperty<float>(gFloatProperties,szName,value,NULL); SetGenericProperty<float>(gFloatProperties,szName,value,NULL);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -584,11 +630,13 @@ ASSIMP_API void aiSetImportPropertyString(const char* szName,
if (!st) { if (!st) {
return; return;
} }
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex); boost::mutex::scoped_lock lock(gMutex);
#endif #endif
SetGenericProperty<std::string>(gStringProperties,szName, SetGenericProperty<std::string>(gStringProperties,szName,
std::string( st->data ),NULL); std::string( st->data ),NULL);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -96,12 +96,12 @@ void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open B3D file " + pFile + "."); throw DeadlyImportError( "Failed to open B3D file " + pFile + ".");
// check whether the .b3d file is large enough to contain // check whether the .b3d file is large enough to contain
// at least one chunk. // at least one chunk.
size_t fileSize = file->FileSize(); size_t fileSize = file->FileSize();
if( fileSize<8 ) throw new ImportErrorException( "B3D File is too small."); if( fileSize<8 ) throw DeadlyImportError( "B3D File is too small.");
_pos=0; _pos=0;
_buf.resize( fileSize ); _buf.resize( fileSize );
@ -113,7 +113,7 @@ void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void B3DImporter::Oops(){ void B3DImporter::Oops(){
throw new ImportErrorException( "B3D Importer - INTERNAL ERROR" ); throw DeadlyImportError( "B3D Importer - INTERNAL ERROR" );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -121,7 +121,7 @@ void B3DImporter::Fail( string str ){
#ifdef DEBUG_B3D #ifdef DEBUG_B3D
cout<<"Error in B3D file data: "<<str<<endl; cout<<"Error in B3D file data: "<<str<<endl;
#endif #endif
throw new ImportErrorException( "B3D Importer - error in B3D file data: "+str ); throw DeadlyImportError( "B3D Importer - error in B3D file data: "+str );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -85,11 +85,11 @@ void BVHLoader::InternReadFile( const std::string& pFile, aiScene* pScene, IOSys
// read file into memory // read file into memory
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open file " + pFile + "."); throw DeadlyImportError( "Failed to open file " + pFile + ".");
size_t fileSize = file->FileSize(); size_t fileSize = file->FileSize();
if( fileSize == 0) if( fileSize == 0)
throw new ImportErrorException( "File is too small."); throw DeadlyImportError( "File is too small.");
mBuffer.resize( fileSize); mBuffer.resize( fileSize);
file->Read( &mBuffer.front(), 1, fileSize); file->Read( &mBuffer.front(), 1, fileSize);
@ -386,7 +386,7 @@ float BVHLoader::GetNextTokenAsFloat()
// Aborts the file reading with an exception // Aborts the file reading with an exception
void BVHLoader::ThrowException( const std::string& pError) void BVHLoader::ThrowException( const std::string& pError)
{ {
throw new ImportErrorException( boost::str( boost::format( "%s:%d - %s") % mFileName % mLine % pError)); throw DeadlyImportError( boost::str( boost::format( "%s:%d - %s") % mFileName % mLine % pError));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -438,7 +438,7 @@ void BVHLoader::CreateAnimation( aiScene* pScene)
case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channel]; break; case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channel]; break;
case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channel]; break; case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channel]; break;
case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channel]; break; case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channel]; break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName ); default: throw DeadlyImportError( "Unexpected animation channel setup at node " + nodeName );
} }
} }
++poskey; ++poskey;
@ -482,7 +482,7 @@ void BVHLoader::CreateAnimation( aiScene* pScene)
case Channel_RotationX: aiMatrix4x4::RotationX( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; case Channel_RotationX: aiMatrix4x4::RotationX( angle, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationY: aiMatrix4x4::RotationY( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; case Channel_RotationY: aiMatrix4x4::RotationY( angle, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationZ: aiMatrix4x4::RotationZ( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; case Channel_RotationZ: aiMatrix4x4::RotationZ( angle, temp); rotMatrix *= aiMatrix3x3( temp); break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName ); default: throw DeadlyImportError( "Unexpected animation channel setup at node " + nodeName );
} }
} }

View File

@ -63,6 +63,25 @@ BaseImporter::~BaseImporter()
// nothing to do here // nothing to do here
} }
template <typename T>
struct tinyguard
{
tinyguard(T* obj) : obj(obj), mdismiss() {}
~tinyguard () throw() {if (!mdismiss) {delete obj;} obj = NULL;}
void dismiss() {
mdismiss=true;
}
operator T*() {
return obj;
}
private:
T* obj;
bool mdismiss;
};
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Imports the given file and returns the imported data. // Imports the given file and returns the imported data.
aiScene* BaseImporter::ReadFile( const std::string& pFile, IOSystem* pIOHandler) aiScene* BaseImporter::ReadFile( const std::string& pFile, IOSystem* pIOHandler)
@ -71,28 +90,23 @@ aiScene* BaseImporter::ReadFile( const std::string& pFile, IOSystem* pIOHandler)
FileSystemFilter filter(pFile,pIOHandler); FileSystemFilter filter(pFile,pIOHandler);
// create a scene object to hold the data // create a scene object to hold the data
aiScene* scene = new aiScene(); tinyguard<aiScene> sc(new aiScene());
// dispatch importing // dispatch importing
try try
{ {
InternReadFile( pFile, scene, &filter); InternReadFile( pFile, sc, &filter);
} catch( ImportErrorException* exception)
{ } catch( const std::exception& err ) {
// extract error description // extract error description
mErrorText = exception->GetErrorText(); mErrorText = err.what();
DefaultLogger::get()->error(mErrorText); DefaultLogger::get()->error(mErrorText);
return NULL;
delete exception;
// and kill the partially imported data
delete scene;
scene = NULL;
} }
// return what we gathered from the import. // return what we gathered from the import.
return scene; sc.dismiss();
return sc;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -269,7 +283,7 @@ void BaseImporter::ConvertToUTF8(std::vector<char>& data)
{ {
ConversionResult result; ConversionResult result;
if(data.size() < 8) { if(data.size() < 8) {
throw new ImportErrorException("File is too small"); throw DeadlyImportError("File is too small");
} }
// UTF 8 with BOM // UTF 8 with BOM
@ -352,13 +366,13 @@ void BaseImporter::TextFileToBuffer(IOStream* stream,
const size_t fileSize = stream->FileSize(); const size_t fileSize = stream->FileSize();
if(!fileSize) { if(!fileSize) {
throw new ImportErrorException("File is empty"); throw DeadlyImportError("File is empty");
} }
data.reserve(fileSize+1); data.reserve(fileSize+1);
data.resize(fileSize); data.resize(fileSize);
if(fileSize != stream->Read( &data[0], 1, fileSize)) { if(fileSize != stream->Read( &data[0], 1, fileSize)) {
throw new ImportErrorException("File read error"); throw DeadlyImportError("File read error");
} }
ConvertToUTF8(data); ConvertToUTF8(data);

View File

@ -42,6 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef INCLUDED_AI_BASEIMPORTER_H #ifndef INCLUDED_AI_BASEIMPORTER_H
#define INCLUDED_AI_BASEIMPORTER_H #define INCLUDED_AI_BASEIMPORTER_H
#include "Exceptional.h"
#include <string> #include <string>
#include "./../include/aiTypes.h" #include "./../include/aiTypes.h"
@ -56,25 +58,6 @@ class Importer;
#define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \ #define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \
(string[1] << 16) + (string[2] << 8) + string[3])) (string[1] << 16) + (string[2] << 8) + string[3]))
// ---------------------------------------------------------------------------
/** FOR IMPORTER PLUGINS ONLY: Simple exception class to be thrown if an
* error occurs while importing. */
class ASSIMP_API ImportErrorException
{
public:
/** Constructor with arguments */
ImportErrorException( const std::string& pErrorText) {
mErrorText = pErrorText;
}
// -------------------------------------------------------------------
/** Returns the error text provided when throwing the exception */
inline const std::string& GetErrorText() const
{ return mErrorText; }
private:
std::string mErrorText;
};
//! @cond never //! @cond never
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -64,20 +64,17 @@ BaseProcess::~BaseProcess()
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void BaseProcess::ExecuteOnScene( Importer* pImp) void BaseProcess::ExecuteOnScene( Importer* pImp)
{ {
ai_assert(NULL != pImp && NULL != pImp->pimpl->mScene); ai_assert(NULL != pImp && NULL != pImp->pimpl->mScene)
// catch exceptions thrown inside the PostProcess-Step // catch exceptions thrown inside the PostProcess-Step
try try
{ {
Execute(pImp->pimpl->mScene); Execute(pImp->pimpl->mScene);
} catch( ImportErrorException* exception) } catch( const std::exception& err ) {
{
// extract error description
pImp->pimpl->mErrorString = exception->GetErrorText();
DefaultLogger::get()->error(pImp->pimpl->mErrorString);
delete exception; // extract error description
pImp->pimpl->mErrorString = err.what();
DefaultLogger::get()->error(pImp->pimpl->mErrorString);
// and kill the partially imported data // and kill the partially imported data
delete pImp->pimpl->mScene; delete pImp->pimpl->mScene;

View File

@ -104,7 +104,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open CSM file " + pFile + "."); throw DeadlyImportError( "Failed to open CSM file " + pFile + ".");
} }
// allocate storage and copy the contents of the file to a memory buffer // allocate storage and copy the contents of the file to a memory buffer
@ -159,7 +159,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
anim->mNumChannels = anims_temp.size(); anim->mNumChannels = anims_temp.size();
if (!anim->mNumChannels) if (!anim->mNumChannels)
throw new ImportErrorException("CSM: Empty $order section"); throw DeadlyImportError("CSM: Empty $order section");
// copy over to the output animation // copy over to the output animation
anim->mChannels = new aiNodeAnim*[anim->mNumChannels]; anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
@ -167,7 +167,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
} }
else if (TokenMatchI(buffer,"points",6)) { else if (TokenMatchI(buffer,"points",6)) {
if (!anim->mNumChannels) if (!anim->mNumChannels)
throw new ImportErrorException("CSM: \'$order\' section is required to appear prior to \'$points\'"); throw DeadlyImportError("CSM: \'$order\' section is required to appear prior to \'$points\'");
// If we know how many frames we'll read, we can preallocate some storage // If we know how many frames we'll read, we can preallocate some storage
unsigned int alloc = 100; unsigned int alloc = 100;
@ -205,7 +205,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
// read x,y,z // read x,y,z
if(!SkipSpacesAndLineEnd(&buffer)) if(!SkipSpacesAndLineEnd(&buffer))
throw new ImportErrorException("CSM: Unexpected EOF occured reading sample x coord"); throw DeadlyImportError("CSM: Unexpected EOF occured reading sample x coord");
if (TokenMatchI(buffer, "DROPOUT", 7)) { if (TokenMatchI(buffer, "DROPOUT", 7)) {
// seems this is invalid marker data; at least the doc says it's possible // seems this is invalid marker data; at least the doc says it's possible
@ -217,11 +217,11 @@ void CSMImporter::InternReadFile( const std::string& pFile,
buffer = fast_atof_move(buffer, (float&)sub->mValue.x); buffer = fast_atof_move(buffer, (float&)sub->mValue.x);
if(!SkipSpacesAndLineEnd(&buffer)) if(!SkipSpacesAndLineEnd(&buffer))
throw new ImportErrorException("CSM: Unexpected EOF occured reading sample y coord"); throw DeadlyImportError("CSM: Unexpected EOF occured reading sample y coord");
buffer = fast_atof_move(buffer, (float&)sub->mValue.y); buffer = fast_atof_move(buffer, (float&)sub->mValue.y);
if(!SkipSpacesAndLineEnd(&buffer)) if(!SkipSpacesAndLineEnd(&buffer))
throw new ImportErrorException("CSM: Unexpected EOF occured reading sample z coord"); throw DeadlyImportError("CSM: Unexpected EOF occured reading sample z coord");
buffer = fast_atof_move(buffer, (float&)sub->mValue.z); buffer = fast_atof_move(buffer, (float&)sub->mValue.z);
++s->mNumPositionKeys; ++s->mNumPositionKeys;
@ -238,7 +238,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
for (unsigned int i = 0; i < anim->mNumChannels;++i) { for (unsigned int i = 0; i < anim->mNumChannels;++i) {
if (!anim->mChannels[i]->mNumPositionKeys) if (!anim->mChannels[i]->mNumPositionKeys)
throw new ImportErrorException("CSM: Invalid marker track"); throw DeadlyImportError("CSM: Invalid marker track");
} }
} }
} }

View File

@ -115,7 +115,7 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
ColladaParser parser( pIOHandler, pFile); ColladaParser parser( pIOHandler, pFile);
if( !parser.mRootNode) if( !parser.mRootNode)
throw new ImportErrorException( "Collada: File came out empty. Something is wrong here."); throw DeadlyImportError( "Collada: File came out empty. Something is wrong here.");
// reserve some storage to avoid unnecessary reallocs // reserve some storage to avoid unnecessary reallocs
newMats.reserve(parser.mMaterialLibrary.size()*2); newMats.reserve(parser.mMaterialLibrary.size()*2);
@ -577,7 +577,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
{ {
// refuse if the vertex count does not match // refuse if the vertex count does not match
// if( pSrcController->mWeightCounts.size() != dstMesh->mNumVertices) // if( pSrcController->mWeightCounts.size() != dstMesh->mNumVertices)
// throw new ImportErrorException( "Joint Controller vertex count does not match mesh vertex count"); // throw DeadlyImportError( "Joint Controller vertex count does not match mesh vertex count");
// resolve references - joint names // resolve references - joint names
const Collada::Accessor& jointNamesAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mJointNameSource); const Collada::Accessor& jointNamesAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mJointNameSource);
@ -588,16 +588,16 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// joint vertex_weight name list - should refer to the same list as the joint names above. If not, report and reconsider // joint vertex_weight name list - should refer to the same list as the joint names above. If not, report and reconsider
const Collada::Accessor& weightNamesAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mWeightInputJoints.mAccessor); const Collada::Accessor& weightNamesAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mWeightInputJoints.mAccessor);
if( &weightNamesAcc != &jointNamesAcc) if( &weightNamesAcc != &jointNamesAcc)
throw new ImportErrorException( "Temporary implementational lazyness. If you read this, please report to the author."); throw DeadlyImportError( "Temporary implementational lazyness. If you read this, please report to the author.");
// vertex weights // vertex weights
const Collada::Accessor& weightsAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mWeightInputWeights.mAccessor); const Collada::Accessor& weightsAcc = pParser.ResolveLibraryReference( pParser.mAccessorLibrary, pSrcController->mWeightInputWeights.mAccessor);
const Collada::Data& weights = pParser.ResolveLibraryReference( pParser.mDataLibrary, weightsAcc.mSource); const Collada::Data& weights = pParser.ResolveLibraryReference( pParser.mDataLibrary, weightsAcc.mSource);
if( !jointNames.mIsStringArray || jointMatrices.mIsStringArray || weights.mIsStringArray) if( !jointNames.mIsStringArray || jointMatrices.mIsStringArray || weights.mIsStringArray)
throw new ImportErrorException( "Data type mismatch while resolving mesh joints"); throw DeadlyImportError( "Data type mismatch while resolving mesh joints");
// sanity check: we rely on the vertex weights always coming as pairs of BoneIndex-WeightIndex // sanity check: we rely on the vertex weights always coming as pairs of BoneIndex-WeightIndex
if( pSrcController->mWeightInputJoints.mOffset != 0 || pSrcController->mWeightInputWeights.mOffset != 1) if( pSrcController->mWeightInputJoints.mOffset != 0 || pSrcController->mWeightInputWeights.mOffset != 1)
throw new ImportErrorException( "Unsupported vertex_weight adresssing scheme. Fucking collada spec."); throw DeadlyImportError( "Unsupported vertex_weight adresssing scheme. Fucking collada spec.");
// create containers to collect the weights for each bone // create containers to collect the weights for each bone
size_t numBones = jointNames.mStrings.size(); size_t numBones = jointNames.mStrings.size();
@ -910,7 +910,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
// time count and value count must match // time count and value count must match
if( e.mTimeAccessor->mCount != e.mValueAccessor->mCount) if( e.mTimeAccessor->mCount != e.mValueAccessor->mCount)
throw new ImportErrorException( boost::str( boost::format( "Time count / value count mismatch in animation channel \"%s\".") % e.mChannel->mTarget)); throw DeadlyImportError( boost::str( boost::format( "Time count / value count mismatch in animation channel \"%s\".") % e.mChannel->mTarget));
// find bounding times // find bounding times
startTime = std::min( startTime, ReadFloat( *e.mTimeAccessor, *e.mTimeData, 0, 0)); startTime = std::min( startTime, ReadFloat( *e.mTimeAccessor, *e.mTimeData, 0, 0));
@ -1282,7 +1282,7 @@ const aiString& ColladaLoader::FindFilenameForEffectTexture( const ColladaParser
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find( name); ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find( name);
if( imIt == pParser.mImageLibrary.end()) if( imIt == pParser.mImageLibrary.end())
{ {
throw new ImportErrorException( boost::str( boost::format( throw DeadlyImportError( boost::str( boost::format(
"Collada: Unable to resolve effect texture entry \"%s\", ended up at ID \"%s\".") % pName % name)); "Collada: Unable to resolve effect texture entry \"%s\", ended up at ID \"%s\".") % pName % name));
} }
@ -1292,7 +1292,7 @@ const aiString& ColladaLoader::FindFilenameForEffectTexture( const ColladaParser
if (imIt->second.mFileName.empty()) if (imIt->second.mFileName.empty())
{ {
if (imIt->second.mImageData.empty()) { if (imIt->second.mImageData.empty()) {
throw new ImportErrorException("Collada: Invalid texture, no data or file reference given"); throw DeadlyImportError("Collada: Invalid texture, no data or file reference given");
} }
aiTexture* tex = new aiTexture(); aiTexture* tex = new aiTexture();

View File

@ -68,7 +68,7 @@ ColladaParser::ColladaParser( IOSystem* pIOHandler, const std::string& pFile)
// open the file // open the file
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open file " + pFile + "."); 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()));
@ -2531,7 +2531,7 @@ void ColladaParser::ReadScene()
// Aborts the file reading with an exception // Aborts the file reading with an exception
void ColladaParser::ThrowException( const std::string& pError) const void ColladaParser::ThrowException( const std::string& pError) const
{ {
throw new ImportErrorException( boost::str( boost::format( "Collada: %s - %s") % mFileName % pError)); throw DeadlyImportError( boost::str( boost::format( "Collada: %s - %s") % mFileName % pError));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -392,7 +392,7 @@ void ComputeUVMappingProcess::Execute( aiScene* pScene)
char buffer[1024]; char buffer[1024];
if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT)
throw new ImportErrorException("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here"); throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here");
std::list<MappingInfo> mappingStack; std::list<MappingInfo> mappingStack;

View File

@ -162,7 +162,7 @@ void DXFImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open DXF file " + pFile + ""); throw DeadlyImportError( "Failed to open DXF file " + pFile + "");
} }
// read the contents of the file in a buffer // read the contents of the file in a buffer
@ -175,7 +175,7 @@ void DXFImporter::InternReadFile( const std::string& pFile,
// check whether this is a binaray DXF file - we can't read binary DXF files :-( // check whether this is a binaray DXF file - we can't read binary DXF files :-(
if (!strncmp(AI_DXF_BINARY_IDENT,buffer,AI_DXF_BINARY_IDENT_LEN)) if (!strncmp(AI_DXF_BINARY_IDENT,buffer,AI_DXF_BINARY_IDENT_LEN))
throw new ImportErrorException("DXF: Binary files are not supported at the moment"); throw DeadlyImportError("DXF: Binary files are not supported at the moment");
// now get all lines of the file // now get all lines of the file
while (GetNextToken()) { while (GetNextToken()) {
@ -212,7 +212,7 @@ void DXFImporter::InternReadFile( const std::string& pFile,
} }
if (!pScene->mNumMeshes) if (!pScene->mNumMeshes)
throw new ImportErrorException("DXF: this file contains no 3d data"); throw DeadlyImportError("DXF: this file contains no 3d data");
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ]; pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
unsigned int m = 0; unsigned int m = 0;

122
code/Exceptional.h 100644
View File

@ -0,0 +1,122 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef INCLUDED_EXCEPTIONAL_H
#define INCLUDED_EXCEPTIONAL_H
#include <stdexcept>
using std::runtime_error;
#ifdef _MSC_VER
# pragma warning(disable : 4275)
#endif
// ---------------------------------------------------------------------------
/** FOR IMPORTER PLUGINS ONLY: Simple exception class to be thrown if an
* unrecoverable error occurs while importing. Loading APIs return
* NULL instead of a valid aiScene then. */
class ASSIMP_API DeadlyImportError
: public runtime_error
{
public:
/** Constructor with arguments */
explicit DeadlyImportError( const std::string& pErrorText)
: runtime_error(pErrorText)
{
}
private:
};
#ifdef _MSC_VER
# pragma warning(default : 4275)
#endif
// ---------------------------------------------------------------------------
template <typename T>
struct ExceptionSwallower {
T operator ()() const {
return T();
}
};
// ---------------------------------------------------------------------------
template <typename T>
struct ExceptionSwallower<T*> {
T* operator ()() const {
return NULL;
}
};
// ---------------------------------------------------------------------------
template <>
struct ExceptionSwallower<aiReturn> {
aiReturn operator ()() const {
try {
throw;
}
catch (std::bad_alloc&) {
return aiReturn_OUTOFMEMORY;
}
catch (...) {
return aiReturn_FAILURE;
}
}
};
// ---------------------------------------------------------------------------
template <>
struct ExceptionSwallower<void> {
void operator ()() const {
return;
}
};
#define ASSIMP_BEGIN_EXCEPTION_REGION()\
{\
try {
#define ASSIMP_END_EXCEPTION_REGION(type)\
} catch(...) {\
return ExceptionSwallower<type>()();\
}\
}
#endif // INCLUDED_EXCEPTIONAL_H

View File

@ -203,7 +203,7 @@ evil_jump_outside:
// (famous last words) // (famous last words)
// OK ... bad idea. // OK ... bad idea.
throw new ImportErrorException("Mesh is empty after removal of degenerated primitives ... WTF!?"); throw DeadlyImportError("Mesh is empty after removal of degenerated primitives ... WTF!?");
} }
} }

View File

@ -147,7 +147,7 @@ void FindInvalidDataProcess::Execute( aiScene* pScene)
if (out) { if (out) {
if ( real != pScene->mNumMeshes) { if ( real != pScene->mNumMeshes) {
if (!real) { if (!real) {
throw new ImportErrorException("No meshes remaining"); throw DeadlyImportError("No meshes remaining");
} }
// we need to remove some meshes. // we need to remove some meshes.

View File

@ -77,7 +77,7 @@ void GenFaceNormalsProcess::Execute( aiScene* pScene)
DefaultLogger::get()->debug("GenFaceNormalsProcess begin"); DefaultLogger::get()->debug("GenFaceNormalsProcess begin");
if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) { if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) {
throw new ImportErrorException("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here"); throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here");
} }
bool bHas = false; bool bHas = false;

View File

@ -88,7 +88,7 @@ void GenVertexNormalsProcess::Execute( aiScene* pScene)
DefaultLogger::get()->debug("GenVertexNormalsProcess begin"); DefaultLogger::get()->debug("GenVertexNormalsProcess begin");
if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT)
throw new ImportErrorException("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here"); throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here");
bool bHas = false; bool bHas = false;
for( unsigned int a = 0; a < pScene->mNumMeshes; a++) for( unsigned int a = 0; a < pScene->mNumMeshes; a++)

View File

@ -102,13 +102,13 @@ void HMPImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open HMP file " + pFile + "."); throw DeadlyImportError( "Failed to open HMP file " + pFile + ".");
// Check whether the HMP file is large enough to contain // Check whether the HMP file is large enough to contain
// at least the file header // at least the file header
const size_t fileSize = file->FileSize(); const size_t fileSize = file->FileSize();
if( fileSize < 50) if( fileSize < 50)
throw new ImportErrorException( "HMP File is too small."); throw DeadlyImportError( "HMP File is too small.");
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
std::vector<uint8_t> buffer(fileSize); std::vector<uint8_t> buffer(fileSize);
@ -151,7 +151,7 @@ void HMPImporter::InternReadFile( const std::string& pFile,
szBuffer[4] = '\0'; szBuffer[4] = '\0';
// We're definitely unable to load this file // We're definitely unable to load this file
throw new ImportErrorException( "Unknown HMP subformat " + pFile + throw DeadlyImportError( "Unknown HMP subformat " + pFile +
". Magic word (" + szBuffer + ") is not known"); ". Magic word (" + szBuffer + ") is not known");
} }
@ -168,25 +168,25 @@ void HMPImporter::ValidateHeader_HMP457( )
if (120 > iFileSize) if (120 > iFileSize)
{ {
throw new ImportErrorException("HMP file is too small (header size is " throw DeadlyImportError("HMP file is too small (header size is "
"120 bytes, this file is smaller)"); "120 bytes, this file is smaller)");
} }
if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y) if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y)
throw new ImportErrorException("Size of triangles in either x or y direction is zero"); throw DeadlyImportError("Size of triangles in either x or y direction is zero");
if(pcHeader->fnumverts_x < 1.0f || (pcHeader->numverts/pcHeader->fnumverts_x) < 1.0f) if(pcHeader->fnumverts_x < 1.0f || (pcHeader->numverts/pcHeader->fnumverts_x) < 1.0f)
throw new ImportErrorException("Number of triangles in either x or y direction is zero"); throw DeadlyImportError("Number of triangles in either x or y direction is zero");
if(!pcHeader->numframes) if(!pcHeader->numframes)
throw new ImportErrorException("There are no frames. At least one should be there"); throw DeadlyImportError("There are no frames. At least one should be there");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HMPImporter::InternReadFile_HMP4( ) void HMPImporter::InternReadFile_HMP4( )
{ {
throw new ImportErrorException("HMP4 is currently not supported"); throw DeadlyImportError("HMP4 is currently not supported");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -439,7 +439,7 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szC
szCursor += sizeof(uint32_t) * 2; szCursor += sizeof(uint32_t) * 2;
iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t); iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
if (!iType) if (!iType)
throw new ImportErrorException("Unable to read HMP7 skin chunk"); throw DeadlyImportError("Unable to read HMP7 skin chunk");
} }
// read width and height // read width and height

View File

@ -883,7 +883,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open IRR file " + pFile + ""); throw DeadlyImportError( "Failed to open IRR file " + pFile + "");
// Construct the irrXML parser // Construct the irrXML parser
CIrrXML_IOStreamReader st(file.get()); CIrrXML_IOStreamReader st(file.get());

View File

@ -103,7 +103,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open IRRMESH file " + pFile + ""); throw DeadlyImportError( "Failed to open IRRMESH file " + pFile + "");
// Construct the irrXML parser // Construct the irrXML parser
CIrrXML_IOStreamReader st(file.get()); CIrrXML_IOStreamReader st(file.get());
@ -227,7 +227,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) { else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
if (curVertices.empty() && curMat) { if (curVertices.empty() && curMat) {
delete curMat; delete curMat;
throw new ImportErrorException("IRRMESH: indices must come after vertices"); throw DeadlyImportError("IRRMESH: indices must come after vertices");
} }
textMeaning = 2; textMeaning = 2;
@ -468,7 +468,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
} }
if (materials.empty()) if (materials.empty())
throw new ImportErrorException("IRRMESH: Unable to read a mesh from this file"); throw DeadlyImportError("IRRMESH: Unable to read a mesh from this file");
// now generate the output scene // now generate the output scene

View File

@ -515,9 +515,12 @@ Importer::Importer(const Importer &other)
aiReturn Importer::RegisterPPStep(BaseProcess* pImp) aiReturn Importer::RegisterPPStep(BaseProcess* pImp)
{ {
ai_assert(NULL != pImp); ai_assert(NULL != pImp);
ASSIMP_BEGIN_EXCEPTION_REGION();
pimpl->mPostProcessingSteps.push_back(pImp); pimpl->mPostProcessingSteps.push_back(pImp);
DefaultLogger::get()->info("Registering custom post-processing step"); DefaultLogger::get()->info("Registering custom post-processing step");
ASSIMP_END_EXCEPTION_REGION(aiReturn);
return AI_SUCCESS; return AI_SUCCESS;
} }
@ -526,6 +529,7 @@ aiReturn Importer::RegisterPPStep(BaseProcess* pImp)
aiReturn Importer::RegisterLoader(BaseImporter* pImp) aiReturn Importer::RegisterLoader(BaseImporter* pImp)
{ {
ai_assert(NULL != pImp); ai_assert(NULL != pImp);
ASSIMP_BEGIN_EXCEPTION_REGION();
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Check whether we would have two loaders for the same file extension // Check whether we would have two loaders for the same file extension
@ -550,6 +554,7 @@ aiReturn Importer::RegisterLoader(BaseImporter* pImp)
// add the loader // add the loader
pimpl->mImporter.push_back(pImp); pimpl->mImporter.push_back(pImp);
DefaultLogger::get()->info("Registering custom importer for these file extensions: " + baked); DefaultLogger::get()->info("Registering custom importer for these file extensions: " + baked);
ASSIMP_END_EXCEPTION_REGION(aiReturn);
return AI_SUCCESS; return AI_SUCCESS;
} }
@ -562,6 +567,7 @@ aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
return AI_SUCCESS; return AI_SUCCESS;
} }
ASSIMP_BEGIN_EXCEPTION_REGION();
std::vector<BaseImporter*>::iterator it = std::find(pimpl->mImporter.begin(),pimpl->mImporter.end(),pImp); std::vector<BaseImporter*>::iterator it = std::find(pimpl->mImporter.begin(),pimpl->mImporter.end(),pImp);
if (it != pimpl->mImporter.end()) { if (it != pimpl->mImporter.end()) {
pimpl->mImporter.erase(it); pimpl->mImporter.erase(it);
@ -573,6 +579,7 @@ aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
return AI_SUCCESS; return AI_SUCCESS;
} }
DefaultLogger::get()->warn("Unable to remove custom importer: I can't find you ..."); DefaultLogger::get()->warn("Unable to remove custom importer: I can't find you ...");
ASSIMP_END_EXCEPTION_REGION(aiReturn);
return AI_FAILURE; return AI_FAILURE;
} }
@ -585,6 +592,7 @@ aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
return AI_SUCCESS; return AI_SUCCESS;
} }
ASSIMP_BEGIN_EXCEPTION_REGION();
std::vector<BaseProcess*>::iterator it = std::find(pimpl->mPostProcessingSteps.begin(),pimpl->mPostProcessingSteps.end(),pImp); std::vector<BaseProcess*>::iterator it = std::find(pimpl->mPostProcessingSteps.begin(),pimpl->mPostProcessingSteps.end(),pImp);
if (it != pimpl->mPostProcessingSteps.end()) { if (it != pimpl->mPostProcessingSteps.end()) {
pimpl->mPostProcessingSteps.erase(it); pimpl->mPostProcessingSteps.erase(it);
@ -592,6 +600,7 @@ aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
return AI_SUCCESS; return AI_SUCCESS;
} }
DefaultLogger::get()->warn("Unable to remove custom post-processing step: I can't find you .."); DefaultLogger::get()->warn("Unable to remove custom post-processing step: I can't find you ..");
ASSIMP_END_EXCEPTION_REGION(aiReturn);
return AI_FAILURE; return AI_FAILURE;
} }
@ -599,6 +608,7 @@ aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
// Supplies a custom IO handler to the importer to open and access files. // Supplies a custom IO handler to the importer to open and access files.
void Importer::SetIOHandler( IOSystem* pIOHandler) void Importer::SetIOHandler( IOSystem* pIOHandler)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
// If the new handler is zero, allocate a default IO implementation. // If the new handler is zero, allocate a default IO implementation.
if (!pIOHandler) if (!pIOHandler)
{ {
@ -613,6 +623,7 @@ void Importer::SetIOHandler( IOSystem* pIOHandler)
pimpl->mIOHandler = pIOHandler; pimpl->mIOHandler = pIOHandler;
pimpl->mIsDefaultHandler = false; pimpl->mIsDefaultHandler = false;
} }
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -648,10 +659,12 @@ bool _ValidateFlags(unsigned int pFlags)
// Free the current scene // Free the current scene
void Importer::FreeScene( ) void Importer::FreeScene( )
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
delete pimpl->mScene; delete pimpl->mScene;
pimpl->mScene = NULL; pimpl->mScene = NULL;
pimpl->mErrorString = ""; pimpl->mErrorString = "";
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -681,9 +694,12 @@ const aiScene* Importer::GetScene() const
aiScene* Importer::GetOrphanedScene() aiScene* Importer::GetOrphanedScene()
{ {
aiScene* s = pimpl->mScene; aiScene* s = pimpl->mScene;
ASSIMP_BEGIN_EXCEPTION_REGION();
pimpl->mScene = NULL; pimpl->mScene = NULL;
pimpl->mErrorString = ""; /* reset error string */ pimpl->mErrorString = ""; /* reset error string */
ASSIMP_END_EXCEPTION_REGION(aiScene*);
return s; return s;
} }
@ -691,9 +707,11 @@ aiScene* Importer::GetOrphanedScene()
// Validate post-processing flags // Validate post-processing flags
bool Importer::ValidateFlags(unsigned int pFlags) bool Importer::ValidateFlags(unsigned int pFlags)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
// run basic checks for mutually exclusive flags // run basic checks for mutually exclusive flags
if(!_ValidateFlags(pFlags)) if(!_ValidateFlags(pFlags)) {
return false; return false;
}
// ValidateDS does not anymore occur in the pp list, it plays an awesome extra role ... // ValidateDS does not anymore occur in the pp list, it plays an awesome extra role ...
#ifdef AI_BUILD_NO_VALIDATEDS_PROCESS #ifdef AI_BUILD_NO_VALIDATEDS_PROCESS
@ -720,6 +738,7 @@ bool Importer::ValidateFlags(unsigned int pFlags)
return false; return false;
} }
} }
ASSIMP_END_EXCEPTION_REGION(bool);
return true; return true;
} }
@ -729,6 +748,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
unsigned int pFlags, unsigned int pFlags,
const char* pHint /*= ""*/) const char* pHint /*= ""*/)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
if (!pHint) { if (!pHint) {
pHint = ""; pHint = "";
} }
@ -751,6 +771,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
ReadFile(fbuff,pFlags); ReadFile(fbuff,pFlags);
SetIOHandler(io); SetIOHandler(io);
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return pimpl->mScene; return pimpl->mScene;
} }
@ -758,6 +779,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
// Reads the given file and returns its contents if successful. // Reads the given file and returns its contents if successful.
const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
const std::string pFile(_pFile); const std::string pFile(_pFile);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -869,6 +891,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
#endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
// either successful or failure - the pointer expresses it anyways // either successful or failure - the pointer expresses it anyways
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return pimpl->mScene; return pimpl->mScene;
} }
@ -876,6 +899,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
// Apply post-processing to the currently bound scene // Apply post-processing to the currently bound scene
const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
// Return immediately if no scene is active // Return immediately if no scene is active
if (!pimpl->mScene) { if (!pimpl->mScene) {
return NULL; return NULL;
@ -948,6 +972,8 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
// clear any data allocated by post-process steps // clear any data allocated by post-process steps
pimpl->mPPShared->Clean(); pimpl->mPPShared->Clean();
DefaultLogger::get()->info("Leaving post processing pipeline"); DefaultLogger::get()->info("Leaving post processing pipeline");
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
return pimpl->mScene; return pimpl->mScene;
} }
@ -963,6 +989,7 @@ bool Importer::IsExtensionSupported(const char* szExtension)
BaseImporter* Importer::FindLoader (const char* szExtension) BaseImporter* Importer::FindLoader (const char* szExtension)
{ {
ai_assert(szExtension); ai_assert(szExtension);
ASSIMP_BEGIN_EXCEPTION_REGION();
// skip over wildcard and dot characters at string head -- // skip over wildcard and dot characters at string head --
for(;*szExtension == '*' || *szExtension == '.'; ++szExtension); for(;*szExtension == '*' || *szExtension == '.'; ++szExtension);
@ -982,6 +1009,7 @@ BaseImporter* Importer::FindLoader (const char* szExtension)
} }
} }
} }
ASSIMP_END_EXCEPTION_REGION(BaseImporter*);
return NULL; return NULL;
} }
@ -989,6 +1017,7 @@ BaseImporter* Importer::FindLoader (const char* szExtension)
// Helper function to build a list of all file extensions supported by ASSIMP // Helper function to build a list of all file extensions supported by ASSIMP
void Importer::GetExtensionList(aiString& szOut) void Importer::GetExtensionList(aiString& szOut)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
std::set<std::string> str; std::set<std::string> str;
for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) { for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
(*i)->GetExtensionList(str); (*i)->GetExtensionList(str);
@ -1003,6 +1032,7 @@ void Importer::GetExtensionList(aiString& szOut)
} }
szOut.Append(";"); szOut.Append(";");
} }
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1010,7 +1040,9 @@ void Importer::GetExtensionList(aiString& szOut)
void Importer::SetPropertyInteger(const char* szName, int iValue, void Importer::SetPropertyInteger(const char* szName, int iValue,
bool* bWasExisting /*= NULL*/) bool* bWasExisting /*= NULL*/)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue,bWasExisting); SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue,bWasExisting);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1018,7 +1050,9 @@ void Importer::SetPropertyInteger(const char* szName, int iValue,
void Importer::SetPropertyFloat(const char* szName, float iValue, void Importer::SetPropertyFloat(const char* szName, float iValue,
bool* bWasExisting /*= NULL*/) bool* bWasExisting /*= NULL*/)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION();
SetGenericProperty<float>(pimpl->mFloatProperties, szName,iValue,bWasExisting); SetGenericProperty<float>(pimpl->mFloatProperties, szName,iValue,bWasExisting);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1026,7 +1060,21 @@ void Importer::SetPropertyFloat(const char* szName, float iValue,
void Importer::SetPropertyString(const char* szName, const std::string& value, void Importer::SetPropertyString(const char* szName, const std::string& value,
bool* bWasExisting /*= NULL*/) bool* bWasExisting /*= NULL*/)
{ {
try {
std::cout << "";
}
catch (...) {
try {
throw;
}
catch(std::exception&) {
return;
}
}
ASSIMP_BEGIN_EXCEPTION_REGION();
SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value,bWasExisting); SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value,bWasExisting);
ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -62,7 +62,7 @@ void LWOImporter::LoadLWOBFile()
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
{ {
throw new ImportErrorException("LWOB: Invalid chunk length"); throw DeadlyImportError("LWOB: Invalid chunk length");
break; break;
} }
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;

View File

@ -609,7 +609,7 @@ struct Surface
#define AI_LWO_VALIDATE_CHUNK_LENGTH(length,name,size) \ #define AI_LWO_VALIDATE_CHUNK_LENGTH(length,name,size) \
if (length < size) \ if (length < size) \
{ \ { \
throw new ImportErrorException("LWO: "#name" chunk is too small"); \ throw DeadlyImportError("LWO: "#name" chunk is too small"); \
} \ } \

View File

@ -105,10 +105,10 @@ void LWOImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open LWO file " + pFile + "."); throw DeadlyImportError( "Failed to open LWO file " + pFile + ".");
if((this->fileSize = (unsigned int)file->FileSize()) < 12) if((this->fileSize = (unsigned int)file->FileSize()) < 12)
throw new ImportErrorException("LWO: The file is too small to contain the IFF header"); throw DeadlyImportError("LWO: The file is too small to contain the IFF header");
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
std::vector< uint8_t > mBuffer(fileSize); std::vector< uint8_t > mBuffer(fileSize);
@ -118,7 +118,7 @@ void LWOImporter::InternReadFile( const std::string& pFile,
// Determine the type of the file // Determine the type of the file
uint32_t fileType; uint32_t fileType;
const char* sz = IFF::ReadHeader(&mBuffer[0],fileType); const char* sz = IFF::ReadHeader(&mBuffer[0],fileType);
if (sz)throw new ImportErrorException(sz); if (sz)throw DeadlyImportError(sz);
mFileBuffer = &mBuffer[0] + 12; mFileBuffer = &mBuffer[0] + 12;
fileSize -= 12; fileSize -= 12;
@ -168,7 +168,7 @@ void LWOImporter::InternReadFile( const std::string& pFile,
szBuff[1] = (char)(fileType >> 16u); szBuff[1] = (char)(fileType >> 16u);
szBuff[2] = (char)(fileType >> 8u); szBuff[2] = (char)(fileType >> 8u);
szBuff[3] = (char)(fileType); szBuff[3] = (char)(fileType);
throw new ImportErrorException(std::string("Unknown LWO sub format: ") + szBuff); throw DeadlyImportError(std::string("Unknown LWO sub format: ") + szBuff);
} }
if (AI_LWO_FOURCC_LWOB != fileType) { if (AI_LWO_FOURCC_LWOB != fileType) {
@ -179,10 +179,10 @@ void LWOImporter::InternReadFile( const std::string& pFile,
// loader that just one layer is used. If this is the case // loader that just one layer is used. If this is the case
// we need to check now whether the requested layer has been found. // we need to check now whether the requested layer has been found.
if (0xffffffff != configLayerIndex && configLayerIndex > mLayers->size()) if (0xffffffff != configLayerIndex && configLayerIndex > mLayers->size())
throw new ImportErrorException("LWO2: The requested layer was not found"); throw DeadlyImportError("LWO2: The requested layer was not found");
if (configLayerName.length() && !hasNamedLayer) { if (configLayerName.length() && !hasNamedLayer) {
throw new ImportErrorException("LWO2: Unable to find the requested layer: " throw DeadlyImportError("LWO2: Unable to find the requested layer: "
+ configLayerName); + configLayerName);
} }
} }
@ -388,7 +388,7 @@ void LWOImporter::InternReadFile( const std::string& pFile,
} }
if (apcNodes.empty() || apcMeshes.empty()) if (apcNodes.empty() || apcMeshes.empty())
throw new ImportErrorException("LWO: No meshes loaded"); throw DeadlyImportError("LWO: No meshes loaded");
// The RemoveRedundantMaterials step will clean this up later // The RemoveRedundantMaterials step will clean this up later
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = (unsigned int)mSurfaces->size()]; pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = (unsigned int)mSurfaces->size()];
@ -586,7 +586,7 @@ void LWOImporter::GenerateNodeGraph(std::vector<aiNode*>& apcNodes)
root->mNumChildren = newSize; root->mNumChildren = newSize;
} }
if (!pScene->mRootNode->mNumChildren) if (!pScene->mRootNode->mNumChildren)
throw new ImportErrorException("LWO: Unable to build a valid node graph"); throw DeadlyImportError("LWO: Unable to build a valid node graph");
// Remove a single root node with no meshes assigned to it ... // Remove a single root node with no meshes assigned to it ...
if (1 == pScene->mRootNode->mNumChildren) { if (1 == pScene->mRootNode->mNumChildren) {
@ -800,7 +800,7 @@ void LWOImporter::CopyFaceIndicesLWO2(FaceList::iterator& it,
} }
} }
} }
else throw new ImportErrorException("LWO2: Encountered invalid face record with zero indices"); else throw DeadlyImportError("LWO2: Encountered invalid face record with zero indices");
} }
} }
@ -1151,7 +1151,7 @@ void LWOImporter::LoadLWO2Envelope(unsigned int length)
LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer); LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer);
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
throw new ImportErrorException("LWO2: Invalid envelope chunk length"); throw DeadlyImportError("LWO2: Invalid envelope chunk length");
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;
switch (head->type) switch (head->type)
@ -1244,7 +1244,7 @@ void LWOImporter::LoadLWO2File()
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
{ {
throw new ImportErrorException("LWO2: Chunk length points behind the file"); throw DeadlyImportError("LWO2: Chunk length points behind the file");
break; break;
} }
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;

View File

@ -528,7 +528,7 @@ void LWOImporter::LoadLWO2ImageMap(unsigned int size, LWO::Texture& tex )
LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer); LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer);
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
throw new ImportErrorException("LWO2: Invalid SURF.BLOCK chunk length"); throw DeadlyImportError("LWO2: Invalid SURF.BLOCK chunk length");
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;
switch (head->type) switch (head->type)
@ -596,7 +596,7 @@ void LWOImporter::LoadLWO2TextureHeader(unsigned int size, LWO::Texture& tex )
LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer); LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer);
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
throw new ImportErrorException("LWO2: Invalid texture header chunk length"); throw DeadlyImportError("LWO2: Invalid texture header chunk length");
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;
switch (head->type) switch (head->type)
@ -699,7 +699,7 @@ void LWOImporter::LoadLWO2ShaderBlock(LE_NCONST IFF::SubChunkHeader* head, unsig
LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer); LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer);
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
throw new ImportErrorException("LWO2: Invalid shader header chunk length"); throw DeadlyImportError("LWO2: Invalid shader header chunk length");
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;
switch (head->type) switch (head->type)
@ -757,7 +757,7 @@ void LWOImporter::LoadLWO2Surface(unsigned int size)
LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer); LE_NCONST IFF::SubChunkHeader* const head = IFF::LoadSubChunk(mFileBuffer);
if (mFileBuffer + head->length > end) if (mFileBuffer + head->length > end)
throw new ImportErrorException("LWO2: Invalid surface chunk length"); throw DeadlyImportError("LWO2: Invalid surface chunk length");
uint8_t* const next = mFileBuffer+head->length; uint8_t* const next = mFileBuffer+head->length;
switch (head->type) switch (head->type)

View File

@ -471,7 +471,7 @@ void LWSImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open LWS file " + pFile + "."); throw DeadlyImportError( "Failed to open LWS file " + pFile + ".");
} }
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
@ -500,7 +500,7 @@ void LWSImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
motion_file = true; motion_file = true;
if ((*it).tokens[0] != "LWSC" && !motion_file) if ((*it).tokens[0] != "LWSC" && !motion_file)
throw new ImportErrorException("LWS: Not a LightWave scene, magic tag LWSC not found"); throw DeadlyImportError("LWS: Not a LightWave scene, magic tag LWSC not found");
// get file format version and print to log // get file format version and print to log
++it; ++it;
@ -808,7 +808,7 @@ void LWSImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
++ no_parent; ++ no_parent;
} }
if (!no_parent) if (!no_parent)
throw new ImportErrorException("LWS: Unable to find scene root node"); throw DeadlyImportError("LWS: Unable to find scene root node");
// Load all subsequent files // Load all subsequent files

View File

@ -131,7 +131,7 @@ void MD2Importer::ValidateHeader( )
szBuffer[3] = ((char*)&m_pcHeader->magic)[3]; szBuffer[3] = ((char*)&m_pcHeader->magic)[3];
szBuffer[4] = '\0'; szBuffer[4] = '\0';
throw new ImportErrorException("Invalid MD2 magic word: should be IDP2, the " throw DeadlyImportError("Invalid MD2 magic word: should be IDP2, the "
"magic word found is " + std::string(szBuffer)); "magic word found is " + std::string(szBuffer));
} }
@ -141,10 +141,10 @@ void MD2Importer::ValidateHeader( )
// check some values whether they are valid // check some values whether they are valid
if (0 == m_pcHeader->numFrames) if (0 == m_pcHeader->numFrames)
throw new ImportErrorException( "Invalid md2 file: NUM_FRAMES is 0"); throw DeadlyImportError( "Invalid md2 file: NUM_FRAMES is 0");
if (m_pcHeader->offsetEnd > (uint32_t)fileSize) if (m_pcHeader->offsetEnd > (uint32_t)fileSize)
throw new ImportErrorException( "Invalid md2 file: File is too small"); throw DeadlyImportError( "Invalid md2 file: File is too small");
if (m_pcHeader->offsetSkins + m_pcHeader->numSkins * sizeof (MD2::Skin) >= fileSize || if (m_pcHeader->offsetSkins + m_pcHeader->numSkins * sizeof (MD2::Skin) >= fileSize ||
m_pcHeader->offsetTexCoords + m_pcHeader->numTexCoords * sizeof (MD2::TexCoord) >= fileSize || m_pcHeader->offsetTexCoords + m_pcHeader->numTexCoords * sizeof (MD2::TexCoord) >= fileSize ||
@ -152,7 +152,7 @@ void MD2Importer::ValidateHeader( )
m_pcHeader->offsetFrames + m_pcHeader->numFrames * sizeof (MD2::Frame) >= fileSize || m_pcHeader->offsetFrames + m_pcHeader->numFrames * sizeof (MD2::Frame) >= fileSize ||
m_pcHeader->offsetEnd > fileSize) m_pcHeader->offsetEnd > fileSize)
{ {
throw new ImportErrorException("Invalid MD2 header: some offsets are outside the file"); throw DeadlyImportError("Invalid MD2 header: some offsets are outside the file");
} }
if (m_pcHeader->numSkins > AI_MD2_MAX_SKINS) if (m_pcHeader->numSkins > AI_MD2_MAX_SKINS)
@ -163,7 +163,7 @@ void MD2Importer::ValidateHeader( )
DefaultLogger::get()->warn("The model contains more vertices than Quake 2 supports"); DefaultLogger::get()->warn("The model contains more vertices than Quake 2 supports");
if (m_pcHeader->numFrames <= configFrameID ) if (m_pcHeader->numFrames <= configFrameID )
throw new ImportErrorException("The requested frame is not existing the file"); throw DeadlyImportError("The requested frame is not existing the file");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -175,13 +175,13 @@ void MD2Importer::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open MD2 file " + pFile + ""); throw DeadlyImportError( "Failed to open MD2 file " + pFile + "");
// check whether the md3 file is large enough to contain // check whether the md3 file is large enough to contain
// at least the file header // at least the file header
fileSize = (unsigned int)file->FileSize(); fileSize = (unsigned int)file->FileSize();
if( fileSize < sizeof(MD2::Header)) if( fileSize < sizeof(MD2::Header))
throw new ImportErrorException( "MD2 File is too small"); throw DeadlyImportError( "MD2 File is too small");
std::vector<uint8_t> mBuffer2(fileSize); std::vector<uint8_t> mBuffer2(fileSize);
file->Read(&mBuffer2[0], 1, fileSize); file->Read(&mBuffer2[0], 1, fileSize);

View File

@ -365,7 +365,7 @@ void MD3Importer::ValidateHeaderOffsets()
// Check magic number // Check magic number
if (pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_BE && if (pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_BE &&
pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_LE) pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_LE)
throw new ImportErrorException( "Invalid MD3 file: Magic bytes not found"); throw DeadlyImportError( "Invalid MD3 file: Magic bytes not found");
// Check file format version // Check file format version
if (pcHeader->VERSION > 15) if (pcHeader->VERSION > 15)
@ -373,15 +373,15 @@ void MD3Importer::ValidateHeaderOffsets()
// Check some offset values whether they are valid // Check some offset values whether they are valid
if (!pcHeader->NUM_SURFACES) if (!pcHeader->NUM_SURFACES)
throw new ImportErrorException( "Invalid md3 file: NUM_SURFACES is 0"); throw DeadlyImportError( "Invalid md3 file: NUM_SURFACES is 0");
if (pcHeader->OFS_FRAMES >= fileSize || pcHeader->OFS_SURFACES >= fileSize || if (pcHeader->OFS_FRAMES >= fileSize || pcHeader->OFS_SURFACES >= fileSize ||
pcHeader->OFS_EOF > fileSize) { pcHeader->OFS_EOF > fileSize) {
throw new ImportErrorException("Invalid MD3 header: some offsets are outside the file"); throw DeadlyImportError("Invalid MD3 header: some offsets are outside the file");
} }
if (pcHeader->NUM_FRAMES <= configFrameID ) if (pcHeader->NUM_FRAMES <= configFrameID )
throw new ImportErrorException("The requested frame is not existing the file"); throw DeadlyImportError("The requested frame is not existing the file");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -396,7 +396,7 @@ void MD3Importer::ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurf)
pcSurf->OFS_ST + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::TexCoord) > fileSize || pcSurf->OFS_ST + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::TexCoord) > fileSize ||
pcSurf->OFS_XYZNORMAL + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::Vertex) > fileSize) { pcSurf->OFS_XYZNORMAL + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::Vertex) > fileSize) {
throw new ImportErrorException("Invalid MD3 surface header: some offsets are outside the file"); throw DeadlyImportError("Invalid MD3 surface header: some offsets are outside the file");
} }
// Check whether all requirements for Q3 files are met. We don't // Check whether all requirements for Q3 files are met. We don't
@ -634,7 +634,7 @@ error_cleanup:
delete master; delete master;
if (failure == mod_filename) { if (failure == mod_filename) {
throw new ImportErrorException("MD3: failure to read multipart host file"); throw DeadlyImportError("MD3: failure to read multipart host file");
} }
} }
return false; return false;
@ -709,12 +709,12 @@ void MD3Importer::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open MD3 file " + pFile + "."); throw DeadlyImportError( "Failed to open MD3 file " + pFile + ".");
// Check whether the md3 file is large enough to contain the header // Check whether the md3 file is large enough to contain the header
fileSize = (unsigned int)file->FileSize(); fileSize = (unsigned int)file->FileSize();
if( fileSize < sizeof(MD3::Header)) if( fileSize < sizeof(MD3::Header))
throw new ImportErrorException( "MD3 File is too small."); throw DeadlyImportError( "MD3 File is too small.");
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
std::vector<unsigned char> mBuffer2 (fileSize); std::vector<unsigned char> mBuffer2 (fileSize);
@ -994,7 +994,7 @@ void MD3Importer::InternReadFile( const std::string& pFile,
} }
if (!pScene->mNumMeshes) if (!pScene->mNumMeshes)
throw new ImportErrorException( "MD3: File contains no valid mesh"); throw DeadlyImportError( "MD3: File contains no valid mesh");
pScene->mNumMaterials = iNumMaterials; pScene->mNumMaterials = iNumMaterials;
// Now we need to generate an empty node graph // Now we need to generate an empty node graph

View File

@ -139,14 +139,15 @@ void MD5Importer::InternReadFile( const std::string& pFile,
LoadMD5AnimFile(); LoadMD5AnimFile();
} }
} }
catch ( ImportErrorException* ex) { catch ( std::exception&) {
// XXX use more idiomatic RAII solution
UnloadFileFromMemory(); UnloadFileFromMemory();
throw ex; throw;
} }
// make sure we have at least one file // make sure we have at least one file
if (!bHadMD5Mesh && !bHadMD5Anim && !bHadMD5Camera) if (!bHadMD5Mesh && !bHadMD5Anim && !bHadMD5Camera)
throw new ImportErrorException("Failed to read valid contents from this MD5* file"); throw DeadlyImportError("Failed to read valid contents from this MD5* file");
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f, pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
@ -207,7 +208,7 @@ void MD5Importer::MakeDataUnique (MD5::MeshDesc& meshSrc)
const aiFace& face = *iter; const aiFace& face = *iter;
for (unsigned int i = 0; i < 3;++i) { for (unsigned int i = 0; i < 3;++i) {
if (face.mIndices[0] >= meshSrc.mVertices.size()) if (face.mIndices[0] >= meshSrc.mVertices.size())
throw new ImportErrorException("MD5MESH: Invalid vertex index"); throw DeadlyImportError("MD5MESH: Invalid vertex index");
if (abHad[face.mIndices[i]]) { if (abHad[face.mIndices[i]]) {
// generate a new vertex // generate a new vertex
@ -455,7 +456,7 @@ void MD5Importer::LoadMD5MeshFile ()
// process bone weights // process bone weights
for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights;++w) { for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights;++w) {
if (w >= meshSrc.mWeights.size()) if (w >= meshSrc.mWeights.size())
throw new ImportErrorException("MD5MESH: Invalid weight index"); throw DeadlyImportError("MD5MESH: Invalid weight index");
MD5::WeightDesc& desc = meshSrc.mWeights[w]; MD5::WeightDesc& desc = meshSrc.mWeights[w];
if ( desc.mWeight < AI_MD5_WEIGHT_EPSILON && desc.mWeight >= -AI_MD5_WEIGHT_EPSILON) if ( desc.mWeight < AI_MD5_WEIGHT_EPSILON && desc.mWeight >= -AI_MD5_WEIGHT_EPSILON)
@ -590,7 +591,7 @@ void MD5Importer::LoadMD5AnimFile ()
// Allow for empty frames // Allow for empty frames
if ((*iter2).iFlags != 0) { if ((*iter2).iFlags != 0) {
throw new ImportErrorException("MD5: Keyframe index is out of range"); throw DeadlyImportError("MD5: Keyframe index is out of range");
} }
continue; continue;
@ -655,7 +656,7 @@ void MD5Importer::LoadMD5CameraFile ()
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException("Failed to read MD5CAMERA file: " + pFile); throw DeadlyImportError("Failed to read MD5CAMERA file: " + pFile);
} }
bHadMD5Camera = true; bHadMD5Camera = true;
LoadFileIntoMemory(file.get()); LoadFileIntoMemory(file.get());
@ -667,7 +668,7 @@ void MD5Importer::LoadMD5CameraFile ()
MD5::MD5CameraParser cameraParser(parser.mSections); MD5::MD5CameraParser cameraParser(parser.mSections);
if (cameraParser.frames.empty()) if (cameraParser.frames.empty())
throw new ImportErrorException("MD5CAMERA: No frames parsed"); throw DeadlyImportError("MD5CAMERA: No frames parsed");
std::vector<unsigned int>& cuts = cameraParser.cuts; std::vector<unsigned int>& cuts = cameraParser.cuts;
std::vector<MD5::CameraAnimFrameDesc>& frames = cameraParser.frames; std::vector<MD5::CameraAnimFrameDesc>& frames = cameraParser.frames;

View File

@ -92,7 +92,7 @@ MD5Parser::MD5Parser(char* _buffer, unsigned int _fileSize )
{ {
char szBuffer[1024]; char szBuffer[1024];
::sprintf(szBuffer,"[MD5] Line %i: %s",line,error); ::sprintf(szBuffer,"[MD5] Line %i: %s",line,error);
throw new ImportErrorException(szBuffer); throw DeadlyImportError(szBuffer);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -130,7 +130,7 @@ void MDCImporter::ValidateHeader()
szBuffer[3] = ((char*)&pcHeader->ulIdent)[3]; szBuffer[3] = ((char*)&pcHeader->ulIdent)[3];
szBuffer[4] = '\0'; szBuffer[4] = '\0';
throw new ImportErrorException("Invalid MDC magic word: should be IDPC, the " throw DeadlyImportError("Invalid MDC magic word: should be IDPC, the "
"magic word found is " + std::string( szBuffer )); "magic word found is " + std::string( szBuffer ));
} }
@ -140,12 +140,12 @@ void MDCImporter::ValidateHeader()
if (pcHeader->ulOffsetBorderFrames + pcHeader->ulNumFrames * sizeof(MDC::Frame) > this->fileSize || if (pcHeader->ulOffsetBorderFrames + pcHeader->ulNumFrames * sizeof(MDC::Frame) > this->fileSize ||
pcHeader->ulOffsetSurfaces + pcHeader->ulNumSurfaces * sizeof(MDC::Surface) > this->fileSize) pcHeader->ulOffsetSurfaces + pcHeader->ulNumSurfaces * sizeof(MDC::Surface) > this->fileSize)
{ {
throw new ImportErrorException("Some of the offset values in the MDC header are invalid " throw DeadlyImportError("Some of the offset values in the MDC header are invalid "
"and point to something behind the file."); "and point to something behind the file.");
} }
if (this->configFrameID >= this->pcHeader->ulNumFrames) if (this->configFrameID >= this->pcHeader->ulNumFrames)
throw new ImportErrorException("The requested frame is not available"); throw DeadlyImportError("The requested frame is not available");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -176,7 +176,7 @@ void MDCImporter::ValidateSurfaceHeader(BE_NCONST MDC::Surface* pcSurf)
pcSurf->ulOffsetFrameBaseFrames + pcSurf->ulNumBaseFrames * 2 > iMax || pcSurf->ulOffsetFrameBaseFrames + pcSurf->ulNumBaseFrames * 2 > iMax ||
(pcSurf->ulNumCompFrames && pcSurf->ulOffsetFrameCompFrames + pcSurf->ulNumCompFrames * 2 > iMax)) (pcSurf->ulNumCompFrames && pcSurf->ulOffsetFrameCompFrames + pcSurf->ulNumCompFrames * 2 > iMax))
{ {
throw new ImportErrorException("Some of the offset values in the MDC surface header " throw DeadlyImportError("Some of the offset values in the MDC surface header "
"are invalid and point somewhere behind the file."); "are invalid and point somewhere behind the file.");
} }
} }
@ -203,12 +203,12 @@ void MDCImporter::InternReadFile(
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open MDC file " + pFile + "."); throw DeadlyImportError( "Failed to open MDC file " + pFile + ".");
// check whether the mdc file is large enough to contain the file header // check whether the mdc file is large enough to contain the file header
fileSize = (unsigned int)file->FileSize(); fileSize = (unsigned int)file->FileSize();
if( fileSize < sizeof(MDC::Header)) if( fileSize < sizeof(MDC::Header))
throw new ImportErrorException( "MDC File is too small."); throw DeadlyImportError( "MDC File is too small.");
std::vector<unsigned char> mBuffer2(fileSize); std::vector<unsigned char> mBuffer2(fileSize);
file->Read( &mBuffer2[0], 1, fileSize); file->Read( &mBuffer2[0], 1, fileSize);
@ -406,7 +406,7 @@ void MDCImporter::InternReadFile(
// create a flat node graph with a root node and one child for each surface // create a flat node graph with a root node and one child for each surface
if (!pScene->mNumMeshes) if (!pScene->mNumMeshes)
throw new ImportErrorException( "Invalid MDC file: File contains no valid mesh"); throw DeadlyImportError( "Invalid MDC file: File contains no valid mesh");
else if (1 == pScene->mNumMeshes) else if (1 == pScene->mNumMeshes)
{ {
pScene->mRootNode = new aiNode(); pScene->mRootNode = new aiNode();

View File

@ -132,17 +132,20 @@ void MDLImporter::InternReadFile( const std::string& pFile,
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open MDL file " + pFile + "."); throw DeadlyImportError( "Failed to open MDL file " + pFile + ".");
}
// This should work for all other types of MDL files, too ... // This should work for all other types of MDL files, too ...
// the quake header is one of the smallest, afaik // the quake header is one of the smallest, afaik
iFileSize = (unsigned int)file->FileSize(); iFileSize = (unsigned int)file->FileSize();
if( iFileSize < sizeof(MDL::Header)) if( iFileSize < sizeof(MDL::Header)) {
throw new ImportErrorException( "MDL File is too small."); throw DeadlyImportError( "MDL File is too small.");
}
// Allocate storage and copy the contents of the file to a memory buffer // Allocate storage and copy the contents of the file to a memory buffer
mBuffer = new unsigned char[iFileSize+1]; std::vector<unsigned char> buffer(iFileSize+1);
mBuffer = &buffer[0];
file->Read( (void*)mBuffer, 1, iFileSize); file->Read( (void*)mBuffer, 1, iFileSize);
// Append a binary zero to the end of the buffer. // Append a binary zero to the end of the buffer.
@ -152,7 +155,7 @@ void MDLImporter::InternReadFile( const std::string& pFile,
const uint32_t iMagicWord = *((uint32_t*)mBuffer); const uint32_t iMagicWord = *((uint32_t*)mBuffer);
// Determine the file subtype and call the appropriate member function // Determine the file subtype and call the appropriate member function
try {
// Original Quake1 format // Original Quake1 format
if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) { if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) {
DefaultLogger::get()->debug("MDL subtype: Quake 1, magic word is IDPO"); DefaultLogger::get()->debug("MDL subtype: Quake 1, magic word is IDPO");
@ -199,25 +202,15 @@ void MDLImporter::InternReadFile( const std::string& pFile,
} }
else { else {
// print the magic word to the log file // print the magic word to the log file
throw new ImportErrorException( "Unknown MDL subformat " + pFile + throw DeadlyImportError( "Unknown MDL subformat " + pFile +
". Magic word (" + std::string((char*)&iMagicWord,4) + ") is not known"); ". Magic word (" + std::string((char*)&iMagicWord,4) + ") is not known");
} }
}
catch (ImportErrorException* ex) {
delete[] mBuffer;
AI_DEBUG_INVALIDATE_PTR(mBuffer);
AI_DEBUG_INVALIDATE_PTR(pIOHandler);
AI_DEBUG_INVALIDATE_PTR(pScene);
throw ex;
}
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f, pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f); 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
// delete the file buffer and cleanup // delete the file buffer and cleanup
delete[] mBuffer;
AI_DEBUG_INVALIDATE_PTR(mBuffer); AI_DEBUG_INVALIDATE_PTR(mBuffer);
AI_DEBUG_INVALIDATE_PTR(pIOHandler); AI_DEBUG_INVALIDATE_PTR(pIOHandler);
AI_DEBUG_INVALIDATE_PTR(pScene); AI_DEBUG_INVALIDATE_PTR(pScene);
@ -229,7 +222,7 @@ void MDLImporter::SizeCheck(const void* szPos)
{ {
if (!szPos || (const unsigned char*)szPos > this->mBuffer + this->iFileSize) if (!szPos || (const unsigned char*)szPos > this->mBuffer + this->iFileSize)
{ {
throw new ImportErrorException("Invalid MDL file. The file is too small " throw DeadlyImportError("Invalid MDL file. The file is too small "
"or contains invalid data."); "or contains invalid data.");
} }
} }
@ -253,7 +246,7 @@ void MDLImporter::SizeCheck(const void* szPos, const char* szFile, unsigned int
::sprintf(szBuffer,"Invalid MDL file. The file is too small " ::sprintf(szBuffer,"Invalid MDL file. The file is too small "
"or contains invalid data (File: %s Line: %i)",szFilePtr,iLine); "or contains invalid data (File: %s Line: %i)",szFilePtr,iLine);
throw new ImportErrorException(szBuffer); throw DeadlyImportError(szBuffer);
} }
} }
@ -263,13 +256,13 @@ void MDLImporter::ValidateHeader_Quake1(const MDL::Header* pcHeader)
{ {
// some values may not be NULL // some values may not be NULL
if (!pcHeader->num_frames) if (!pcHeader->num_frames)
throw new ImportErrorException( "[Quake 1 MDL] There are no frames in the file"); throw DeadlyImportError( "[Quake 1 MDL] There are no frames in the file");
if (!pcHeader->num_verts) if (!pcHeader->num_verts)
throw new ImportErrorException( "[Quake 1 MDL] There are no vertices in the file"); throw DeadlyImportError( "[Quake 1 MDL] There are no vertices in the file");
if (!pcHeader->num_tris) if (!pcHeader->num_tris)
throw new ImportErrorException( "[Quake 1 MDL] There are no triangles in the file"); throw DeadlyImportError( "[Quake 1 MDL] There are no triangles in the file");
// check whether the maxima are exceeded ...however, this applies for Quake 1 MDLs only // check whether the maxima are exceeded ...however, this applies for Quake 1 MDLs only
if (!this->iGSFileVersion) if (!this->iGSFileVersion)
@ -837,21 +830,21 @@ void MDLImporter::ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7* pcHeader)
// There are some fixed sizes ... // There are some fixed sizes ...
if (sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size) { if (sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size) {
throw new ImportErrorException( throw DeadlyImportError(
"[3DGS MDL7] sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size"); "[3DGS MDL7] sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size");
} }
if (sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size) { if (sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size) {
throw new ImportErrorException( throw DeadlyImportError(
"[3DGS MDL7] sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size"); "[3DGS MDL7] sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size");
} }
if (sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size) { if (sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size) {
throw new ImportErrorException( throw DeadlyImportError(
"sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size"); "sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size");
} }
// if there are no groups ... how should we load such a file? // if there are no groups ... how should we load such a file?
if(!pcHeader->groups_num) { if(!pcHeader->groups_num) {
throw new ImportErrorException( "[3DGS MDL7] No frames found"); throw DeadlyImportError( "[3DGS MDL7] No frames found");
} }
} }

View File

@ -118,7 +118,7 @@ void MS3DImporter :: ReadComments(StreamReaderLE& stream, std::vector<T>& outp)
DefaultLogger::get()->warn("MS3D: Invalid index in comment section"); DefaultLogger::get()->warn("MS3D: Invalid index in comment section");
} }
else if (clength > stream.GetRemainingSize()) { else if (clength > stream.GetRemainingSize()) {
throw new ImportErrorException("MS3D: Failure reading comment, length field is out of range"); throw DeadlyImportError("MS3D: Failure reading comment, length field is out of range");
} }
else { else {
outp[index].comment = std::string(reinterpret_cast<char*>(stream.GetPtr()),clength); outp[index].comment = std::string(reinterpret_cast<char*>(stream.GetPtr()),clength);
@ -203,11 +203,11 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
stream.CopyAndAdvance(head,10); stream.CopyAndAdvance(head,10);
stream >> version; stream >> version;
if (strncmp(head,"MS3D000000",10)) { if (strncmp(head,"MS3D000000",10)) {
throw new ImportErrorException("Not a MS3D file, magic string MS3D000000 not found: "+pFile); throw DeadlyImportError("Not a MS3D file, magic string MS3D000000 not found: "+pFile);
} }
if (version != 4) { if (version != 4) {
throw new ImportErrorException("MS3D: Unsupported file format version, 4 was expected"); throw DeadlyImportError("MS3D: Unsupported file format version, 4 was expected");
} }
uint16_t verts; uint16_t verts;
@ -355,7 +355,7 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
if (stream.GetI4()) { if (stream.GetI4()) {
const size_t len = static_cast<size_t>(stream.GetI4()); const size_t len = static_cast<size_t>(stream.GetI4());
if (len > stream.GetRemainingSize()) { if (len > stream.GetRemainingSize()) {
throw new ImportErrorException("MS3D: Model comment is too long"); throw DeadlyImportError("MS3D: Model comment is too long");
} }
const std::string& s = std::string(reinterpret_cast<char*>(stream.GetPtr()),len); const std::string& s = std::string(reinterpret_cast<char*>(stream.GetPtr()),len);
@ -442,7 +442,7 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
// convert groups to meshes // convert groups to meshes
if (groups.empty()) { if (groups.empty()) {
throw new ImportErrorException("MS3D: Didn't get any group records, file is malformed"); throw DeadlyImportError("MS3D: Didn't get any group records, file is malformed");
} }
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes=static_cast<unsigned int>(groups.size())](); pScene->mMeshes = new aiMesh*[pScene->mNumMeshes=static_cast<unsigned int>(groups.size())]();
@ -452,7 +452,7 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
const TempGroup& g = groups[i]; const TempGroup& g = groups[i];
if (pScene->mNumMaterials && g.mat > pScene->mNumMaterials) { if (pScene->mNumMaterials && g.mat > pScene->mNumMaterials) {
throw new ImportErrorException("MS3D: Encountered invalid material index, file is malformed"); throw DeadlyImportError("MS3D: Encountered invalid material index, file is malformed");
} // no error if no materials at all - scenepreprocessor adds one then } // no error if no materials at all - scenepreprocessor adds one then
m->mMaterialIndex = g.mat; m->mMaterialIndex = g.mat;
@ -473,7 +473,7 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
for (unsigned int i = 0,n = 0; i < m->mNumFaces; ++i) { for (unsigned int i = 0,n = 0; i < m->mNumFaces; ++i) {
aiFace& f = m->mFaces[i]; aiFace& f = m->mFaces[i];
if (g.triangles[i]>triangles.size()) { if (g.triangles[i]>triangles.size()) {
throw new ImportErrorException("MS3D: Encountered invalid triangle index, file is malformed"); throw DeadlyImportError("MS3D: Encountered invalid triangle index, file is malformed");
} }
TempTriangle& t = triangles[g.triangles[i]]; TempTriangle& t = triangles[g.triangles[i]];
@ -481,14 +481,14 @@ void MS3DImporter::InternReadFile( const std::string& pFile,
for (unsigned int i = 0; i < 3; ++i,++n) { for (unsigned int i = 0; i < 3; ++i,++n) {
if (t.indices[i]>vertices.size()) { if (t.indices[i]>vertices.size()) {
throw new ImportErrorException("MS3D: Encountered invalid vertex index, file is malformed"); throw DeadlyImportError("MS3D: Encountered invalid vertex index, file is malformed");
} }
const TempVertex& v = vertices[t.indices[i]]; const TempVertex& v = vertices[t.indices[i]];
for(unsigned int a = 0; a < 4; ++a) { for(unsigned int a = 0; a < 4; ++a) {
if (v.bone_id[a] != 0xffffffff) { if (v.bone_id[a] != 0xffffffff) {
if (v.bone_id[a] >= joints.size()) { if (v.bone_id[a] >= joints.size()) {
throw new ImportErrorException("MS3D: Encountered invalid bone index, file is malformed"); throw DeadlyImportError("MS3D: Encountered invalid bone index, file is malformed");
} }
if (mybones.find(v.bone_id[a]) == mybones.end()) { if (mybones.find(v.bone_id[a]) == mybones.end()) {
mybones[v.bone_id[a]] = 1; mybones[v.bone_id[a]] = 1;

View File

@ -221,7 +221,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( !file.get()) if( !file.get())
throw new ImportErrorException( "Failed to open NFF file " + pFile + "."); throw DeadlyImportError( "Failed to open NFF file " + pFile + ".");
unsigned int m = (unsigned int)file->FileSize(); unsigned int m = (unsigned int)file->FileSize();
@ -428,7 +428,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
} }
AI_NFF2_GET_NEXT_TOKEN(); AI_NFF2_GET_NEXT_TOKEN();
if (!num)throw new ImportErrorException("NFF2: There are zero vertices"); if (!num)throw DeadlyImportError("NFF2: There are zero vertices");
num = ::strtol10(sz,&sz); num = ::strtol10(sz,&sz);
std::vector<unsigned int> tempIdx; std::vector<unsigned int> tempIdx;
@ -637,7 +637,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
} }
} }
} }
if (!num)throw new ImportErrorException("NFF2: There are zero faces"); if (!num)throw DeadlyImportError("NFF2: There are zero faces");
} }
} }
camLookAt = camLookAt + camPos; camLookAt = camLookAt + camPos;
@ -1108,7 +1108,7 @@ void NFFImporter::InternReadFile( const std::string& pFile,
} }
} }
if (!pScene->mNumMeshes)throw new ImportErrorException("NFF: No meshes loaded"); if (!pScene->mNumMeshes)throw DeadlyImportError("NFF: No meshes loaded");
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = pScene->mNumMeshes]; pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = pScene->mNumMeshes];
for (it = meshes.begin(), m = 0; it != end;++it) for (it = meshes.begin(), m = 0; it != end;++it)

View File

@ -96,7 +96,7 @@ void OFFImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open OFF file " + pFile + "."); throw DeadlyImportError( "Failed to open OFF file " + pFile + ".");
} }
// allocate storage and copy the contents of the file to a memory buffer // allocate storage and copy the contents of the file to a memory buffer
@ -158,7 +158,7 @@ void OFFImporter::InternReadFile( const std::string& pFile,
} }
if (!mesh->mNumVertices) if (!mesh->mNumVertices)
throw new ImportErrorException("OFF: There are no valid faces"); throw DeadlyImportError("OFF: There are no valid faces");
// allocate storage for the output vertices // allocate storage for the output vertices
aiVector3D* verts = mesh->mVertices = new aiVector3D[mesh->mNumVertices]; aiVector3D* verts = mesh->mVertices = new aiVector3D[mesh->mNumVertices];

View File

@ -100,12 +100,12 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
const std::string mode = "rb"; const std::string mode = "rb";
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, mode)); boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, mode));
if (NULL == file.get()) if (NULL == file.get())
throw new ImportErrorException( "Failed to open file " + pFile + "."); throw DeadlyImportError( "Failed to open file " + pFile + ".");
// Get the filesize and vaslidate it, throwing an exception when failes // Get the filesize and vaslidate it, throwing an exception when failes
size_t fileSize = file->FileSize(); size_t fileSize = file->FileSize();
if( fileSize < 16) if( fileSize < 16)
throw new ImportErrorException( "OBJ-file is too small."); throw DeadlyImportError( "OBJ-file is too small.");
// Allocate buffer and read file into it // Allocate buffer and read file into it
TextFileToBuffer(file.get(),m_Buffer); TextFileToBuffer(file.get(),m_Buffer);

View File

@ -46,13 +46,13 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
//Open the File: //Open the File:
boost::scoped_ptr<IOStream> file(pIOHandler->Open(pFile)); boost::scoped_ptr<IOStream> file(pIOHandler->Open(pFile));
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException("Failed to open file "+pFile+"."); throw DeadlyImportError("Failed to open file "+pFile+".");
//Read the Mesh File: //Read the Mesh File:
boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper( new CIrrXML_IOStreamReader( file.get())); boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper( new CIrrXML_IOStreamReader( file.get()));
XmlReader* MeshFile = irr::io::createIrrXMLReader(mIOWrapper.get()); XmlReader* MeshFile = irr::io::createIrrXMLReader(mIOWrapper.get());
if(!MeshFile)//parse the xml file if(!MeshFile)//parse the xml file
throw new ImportErrorException("Failed to create XML Reader for "+pFile); throw DeadlyImportError("Failed to create XML Reader for "+pFile);
DefaultLogger::get()->debug("Mesh File opened"); DefaultLogger::get()->debug("Mesh File opened");
@ -60,13 +60,13 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
//Read root Node: //Read root Node:
if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="mesh")) if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="mesh"))
{ {
throw new ImportErrorException("Root Node is not <mesh>! "+pFile+" "+MeshFile->getNodeName()); throw DeadlyImportError("Root Node is not <mesh>! "+pFile+" "+MeshFile->getNodeName());
} }
//Go to the submeshs: //Go to the submeshs:
if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="submeshes")) if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="submeshes"))
{ {
throw new ImportErrorException("No <submeshes> node in <mesh> node! "+pFile); throw DeadlyImportError("No <submeshes> node in <mesh> node! "+pFile);
} }
@ -84,7 +84,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
//Set the Material: //Set the Material:
if(m_CurrentScene->mMaterials) if(m_CurrentScene->mMaterials)
throw new ImportErrorException("only 1 material supported at this time!"); throw DeadlyImportError("only 1 material supported at this time!");
m_CurrentScene->mMaterials=new aiMaterial*[1]; m_CurrentScene->mMaterials=new aiMaterial*[1];
m_CurrentScene->mNumMaterials=1; m_CurrentScene->mNumMaterials=1;
m_CurrentScene->mMaterials[0]=MeshMat; m_CurrentScene->mMaterials[0]=MeshMat;
@ -92,7 +92,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
} }
//check for second root node: //check for second root node:
if(MeshFile->getNodeName()==string("submesh")) if(MeshFile->getNodeName()==string("submesh"))
throw new ImportErrorException("more than one submesh in the file, abording!"); throw DeadlyImportError("more than one submesh in the file, abording!");
//____________________________________________________________ //____________________________________________________________
@ -161,7 +161,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
NewFace.VertexIndices[2]=GetAttribute<int>(Reader, "v3"); NewFace.VertexIndices[2]=GetAttribute<int>(Reader, "v3");
if(Reader->getAttributeValue("v4"))//this should be supported in the future if(Reader->getAttributeValue("v4"))//this should be supported in the future
{ {
throw new ImportErrorException("Submesh has quads, only traingles are supported!"); throw DeadlyImportError("Submesh has quads, only traingles are supported!");
} }
theSubMesh.FaceList.push_back(NewFace); theSubMesh.FaceList.push_back(NewFace);
} }
@ -178,7 +178,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
XmlRead(Reader); XmlRead(Reader);
if(!(Reader->getNodeName()==string("vertexbuffer"))) if(!(Reader->getNodeName()==string("vertexbuffer")))
{ {
throw new ImportErrorException("vertexbuffer node is not first in geometry node!"); throw DeadlyImportError("vertexbuffer node is not first in geometry node!");
} }
theSubMesh.HasPositions=GetAttribute<bool>(Reader, "positions"); theSubMesh.HasPositions=GetAttribute<bool>(Reader, "positions");
theSubMesh.HasNormals=GetAttribute<bool>(Reader, "normals"); theSubMesh.HasNormals=GetAttribute<bool>(Reader, "normals");
@ -187,7 +187,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
else else
theSubMesh.NumUvs=GetAttribute<int>(Reader, "texture_coords"); theSubMesh.NumUvs=GetAttribute<int>(Reader, "texture_coords");
if(theSubMesh.NumUvs>1) if(theSubMesh.NumUvs>1)
throw new ImportErrorException("too many texcoords (just 1 supported!)"); throw DeadlyImportError("too many texcoords (just 1 supported!)");
//read all the vertices: //read all the vertices:
XmlRead(Reader); XmlRead(Reader);
@ -307,7 +307,7 @@ void OgreImporter::CreateAssimpSubMesh(const SubMesh& theSubMesh, const vector<B
{ {
//Mesh is fully loaded, copy it into the aiScene: //Mesh is fully loaded, copy it into the aiScene:
if(m_CurrentScene->mNumMeshes!=0) if(m_CurrentScene->mNumMeshes!=0)
throw new ImportErrorException("Currently only one mesh per File is allowed!!"); throw DeadlyImportError("Currently only one mesh per File is allowed!!");
aiMesh* NewAiMesh=new aiMesh(); aiMesh* NewAiMesh=new aiMesh();
@ -461,7 +461,7 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName)
{ {
ss >> Line; ss >> Line;
if(Line!="{") if(Line!="{")
throw new ImportErrorException("empty material!"); throw DeadlyImportError("empty material!");
while(Line!="}")//read until the end of the material while(Line!="}")//read until the end of the material
{ {
@ -471,7 +471,7 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName)
{ {
ss >> Line; ss >> Line;
if(Line!="{") if(Line!="{")
throw new ImportErrorException("empty technique!"); throw DeadlyImportError("empty technique!");
while(Line!="}")//read until the end of the technique while(Line!="}")//read until the end of the technique
{ {
ss >> Line; ss >> Line;
@ -479,7 +479,7 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName)
{ {
ss >> Line; ss >> Line;
if(Line!="{") if(Line!="{")
throw new ImportErrorException("empty pass!"); throw DeadlyImportError("empty pass!");
while(Line!="}")//read until the end of the pass while(Line!="}")//read until the end of the pass
{ {
ss >> Line; ss >> Line;
@ -500,7 +500,7 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName)
{ {
ss >> Line; ss >> Line;
if(Line!="{") if(Line!="{")
throw new ImportErrorException("empty texture unit!"); throw DeadlyImportError("empty texture unit!");
while(Line!="}")//read until the end of the texture_unit while(Line!="}")//read until the end of the texture_unit
{ {
ss >> Line; ss >> Line;
@ -569,26 +569,26 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Open the File: //Open the File:
boost::scoped_ptr<IOStream> File(m_CurrentIOHandler->Open(FileName)); boost::scoped_ptr<IOStream> File(m_CurrentIOHandler->Open(FileName));
if(NULL==File.get()) if(NULL==File.get())
throw new ImportErrorException("Failed to open skeleton file "+FileName+"."); throw DeadlyImportError("Failed to open skeleton file "+FileName+".");
//Read the Mesh File: //Read the Mesh File:
boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper(new CIrrXML_IOStreamReader(File.get())); boost::scoped_ptr<CIrrXML_IOStreamReader> mIOWrapper(new CIrrXML_IOStreamReader(File.get()));
XmlReader* SkeletonFile = irr::io::createIrrXMLReader(mIOWrapper.get()); XmlReader* SkeletonFile = irr::io::createIrrXMLReader(mIOWrapper.get());
if(!SkeletonFile) if(!SkeletonFile)
throw new ImportErrorException(string("Failed to create XML Reader for ")+FileName); throw DeadlyImportError(string("Failed to create XML Reader for ")+FileName);
//Quick note: Whoever read this should know this one thing: irrXml fucking sucks!!! //Quick note: Whoever read this should know this one thing: irrXml fucking sucks!!!
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("skeleton")!=SkeletonFile->getNodeName()) if(string("skeleton")!=SkeletonFile->getNodeName())
throw new ImportErrorException("No <skeleton> node in SkeletonFile: "+FileName); throw DeadlyImportError("No <skeleton> node in SkeletonFile: "+FileName);
//------------------------------------load bones----------------------------------------- //------------------------------------load bones-----------------------------------------
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("bones")!=SkeletonFile->getNodeName()) if(string("bones")!=SkeletonFile->getNodeName())
throw new ImportErrorException("No bones node in skeleton "+FileName); throw DeadlyImportError("No bones node in skeleton "+FileName);
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
@ -604,7 +604,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//load the position: //load the position:
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("position")!=SkeletonFile->getNodeName()) if(string("position")!=SkeletonFile->getNodeName())
throw new ImportErrorException("Position is not first node in Bone!"); throw DeadlyImportError("Position is not first node in Bone!");
NewBone.Position.x=GetAttribute<float>(SkeletonFile, "x"); NewBone.Position.x=GetAttribute<float>(SkeletonFile, "x");
NewBone.Position.y=GetAttribute<float>(SkeletonFile, "y"); NewBone.Position.y=GetAttribute<float>(SkeletonFile, "y");
NewBone.Position.z=GetAttribute<float>(SkeletonFile, "z"); NewBone.Position.z=GetAttribute<float>(SkeletonFile, "z");
@ -612,11 +612,11 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Rotation: //Rotation:
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("rotation")!=SkeletonFile->getNodeName()) if(string("rotation")!=SkeletonFile->getNodeName())
throw new ImportErrorException("Rotation is not the second node in Bone!"); throw DeadlyImportError("Rotation is not the second node in Bone!");
NewBone.RotationAngle=GetAttribute<float>(SkeletonFile, "angle"); NewBone.RotationAngle=GetAttribute<float>(SkeletonFile, "angle");
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("axis")!=SkeletonFile->getNodeName()) if(string("axis")!=SkeletonFile->getNodeName())
throw new ImportErrorException("No axis specified for bone rotation!"); throw DeadlyImportError("No axis specified for bone rotation!");
NewBone.RotationAxis.x=GetAttribute<float>(SkeletonFile, "x"); NewBone.RotationAxis.x=GetAttribute<float>(SkeletonFile, "x");
NewBone.RotationAxis.y=GetAttribute<float>(SkeletonFile, "y"); NewBone.RotationAxis.y=GetAttribute<float>(SkeletonFile, "y");
NewBone.RotationAxis.z=GetAttribute<float>(SkeletonFile, "z"); NewBone.RotationAxis.z=GetAttribute<float>(SkeletonFile, "z");
@ -639,7 +639,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
IdsOk=false; IdsOk=false;
} }
if(!IdsOk) if(!IdsOk)
throw new ImportErrorException("Bone Ids are not valid!"+FileName); throw DeadlyImportError("Bone Ids are not valid!"+FileName);
} }
DefaultLogger::get()->debug(str(format("Number of bones: %1%") % Bones.size())); DefaultLogger::get()->debug(str(format("Number of bones: %1%") % Bones.size()));
//________________________________________________________________________________ //________________________________________________________________________________
@ -651,7 +651,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//----------------------------load bonehierarchy-------------------------------- //----------------------------load bonehierarchy--------------------------------
if(string("bonehierarchy")!=SkeletonFile->getNodeName()) if(string("bonehierarchy")!=SkeletonFile->getNodeName())
throw new ImportErrorException("no bonehierarchy node in "+FileName); throw DeadlyImportError("no bonehierarchy node in "+FileName);
DefaultLogger::get()->debug("loading bonehierarchy..."); DefaultLogger::get()->debug("loading bonehierarchy...");
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
@ -698,7 +698,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Load all Tracks //Load all Tracks
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("tracks")!=SkeletonFile->getNodeName()) if(string("tracks")!=SkeletonFile->getNodeName())
throw new ImportErrorException("no tracks node in animation"); throw DeadlyImportError("no tracks node in animation");
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
while(string("track")==SkeletonFile->getNodeName()) while(string("track")==SkeletonFile->getNodeName())
{ {
@ -708,7 +708,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Load all keyframes; //Load all keyframes;
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("keyframes")!=SkeletonFile->getNodeName()) if(string("keyframes")!=SkeletonFile->getNodeName())
throw new ImportErrorException("no keyframes node!"); throw DeadlyImportError("no keyframes node!");
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
while(string("keyframe")==SkeletonFile->getNodeName()) while(string("keyframe")==SkeletonFile->getNodeName())
{ {
@ -719,7 +719,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//It seams that we have to flip some axies, i really dont know why //It seams that we have to flip some axies, i really dont know why
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("translate")!=SkeletonFile->getNodeName()) if(string("translate")!=SkeletonFile->getNodeName())
throw new ImportErrorException("translate node not first in keyframe"); throw DeadlyImportError("translate node not first in keyframe");
NewKeyframe.Position.x=GetAttribute<float>(SkeletonFile, "y"); NewKeyframe.Position.x=GetAttribute<float>(SkeletonFile, "y");
NewKeyframe.Position.y=-GetAttribute<float>(SkeletonFile, "z"); NewKeyframe.Position.y=-GetAttribute<float>(SkeletonFile, "z");
NewKeyframe.Position.z=-GetAttribute<float>(SkeletonFile, "x"); NewKeyframe.Position.z=-GetAttribute<float>(SkeletonFile, "x");
@ -727,12 +727,12 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Rotation: //Rotation:
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("rotate")!=SkeletonFile->getNodeName()) if(string("rotate")!=SkeletonFile->getNodeName())
throw new ImportErrorException("rotate is not second node in keyframe"); throw DeadlyImportError("rotate is not second node in keyframe");
float RotationAngle=GetAttribute<float>(SkeletonFile, "angle"); float RotationAngle=GetAttribute<float>(SkeletonFile, "angle");
aiVector3D RotationAxis; aiVector3D RotationAxis;
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("axis")!=SkeletonFile->getNodeName()) if(string("axis")!=SkeletonFile->getNodeName())
throw new ImportErrorException("No axis for keyframe rotation!"); throw DeadlyImportError("No axis for keyframe rotation!");
RotationAxis.x=GetAttribute<float>(SkeletonFile, "x"); RotationAxis.x=GetAttribute<float>(SkeletonFile, "x");
RotationAxis.y=GetAttribute<float>(SkeletonFile, "y"); RotationAxis.y=GetAttribute<float>(SkeletonFile, "y");
RotationAxis.z=GetAttribute<float>(SkeletonFile, "z"); RotationAxis.z=GetAttribute<float>(SkeletonFile, "z");
@ -741,7 +741,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
//Scaling: //Scaling:
XmlRead(SkeletonFile); XmlRead(SkeletonFile);
if(string("scale")!=SkeletonFile->getNodeName()) if(string("scale")!=SkeletonFile->getNodeName())
throw new ImportErrorException("no scalling key in keyframe!"); throw DeadlyImportError("no scalling key in keyframe!");
NewKeyframe.Scaling.x=GetAttribute<float>(SkeletonFile, "x"); NewKeyframe.Scaling.x=GetAttribute<float>(SkeletonFile, "x");
NewKeyframe.Scaling.y=GetAttribute<float>(SkeletonFile, "y"); NewKeyframe.Scaling.y=GetAttribute<float>(SkeletonFile, "y");
NewKeyframe.Scaling.z=GetAttribute<float>(SkeletonFile, "z"); NewKeyframe.Scaling.z=GetAttribute<float>(SkeletonFile, "z");
@ -768,9 +768,9 @@ void OgreImporter::CreateAssimpSkeleton(const std::vector<Bone> &Bones, const st
//-----------------skeleton is completly loaded, now but it in the assimp scene:------------------------------- //-----------------skeleton is completly loaded, now but it in the assimp scene:-------------------------------
if(!m_CurrentScene->mRootNode) if(!m_CurrentScene->mRootNode)
throw new ImportErrorException("No root node exists!!"); throw DeadlyImportError("No root node exists!!");
if(0!=m_CurrentScene->mRootNode->mNumChildren) if(0!=m_CurrentScene->mRootNode->mNumChildren)
throw new ImportErrorException("Root Node already has childnodes!"); throw DeadlyImportError("Root Node already has childnodes!");
//--------------Createt the assimp bone hierarchy----------------- //--------------Createt the assimp bone hierarchy-----------------
DefaultLogger::get()->debug("Root Bones"); DefaultLogger::get()->debug("Root Bones");

View File

@ -23,7 +23,7 @@ template<> inline int GetAttribute<int>(XmlReader* Reader, std::string Name)
if(Value) if(Value)
return atoi(Value); return atoi(Value);
else else
throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
} }
template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name) template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
@ -32,7 +32,7 @@ template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
if(Value) if(Value)
return fast_atof(Value); return fast_atof(Value);
else else
throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
} }
template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name) template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name)
@ -41,7 +41,7 @@ template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::
if(Value) if(Value)
return std::string(Value); return std::string(Value);
else else
throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
} }
template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name) template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
@ -54,10 +54,10 @@ template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
else if(Value==std::string("false")) else if(Value==std::string("false"))
return false; return false;
else else
throw new ImportErrorException(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName())); throw DeadlyImportError(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName()));
} }
else else
throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
} }
//__________________________________________________________________ //__________________________________________________________________

View File

@ -129,7 +129,7 @@ void OptimizeMeshesProcess::Execute( aiScene* pScene)
// and process all nodes in the scenegraoh recursively // and process all nodes in the scenegraoh recursively
ProcessNode(pScene->mRootNode); ProcessNode(pScene->mRootNode);
if (!output.size()) { if (!output.size()) {
throw new ImportErrorException("OptimizeMeshes: No meshes remaining; there's definitely something wrong"); throw DeadlyImportError("OptimizeMeshes: No meshes remaining; there's definitely something wrong");
} }
meshes.clear(); meshes.clear();

View File

@ -94,7 +94,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open PLY file " + pFile + "."); throw DeadlyImportError( "Failed to open PLY file " + pFile + ".");
} }
// allocate storage and copy the contents of the file to a memory buffer // allocate storage and copy the contents of the file to a memory buffer
@ -106,7 +106,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
if ((mBuffer[0] != 'P' && mBuffer[0] != 'p') || if ((mBuffer[0] != 'P' && mBuffer[0] != 'p') ||
(mBuffer[1] != 'L' && mBuffer[1] != 'l') || (mBuffer[1] != 'L' && mBuffer[1] != 'l') ||
(mBuffer[2] != 'Y' && mBuffer[2] != 'y')) { (mBuffer[2] != 'Y' && mBuffer[2] != 'y')) {
throw new ImportErrorException( "Invalid .ply file: Magic number \'ply\' is no there"); throw DeadlyImportError( "Invalid .ply file: Magic number \'ply\' is no there");
} }
char* szMe = (char*)&this->mBuffer[3]; char* szMe = (char*)&this->mBuffer[3];
@ -120,7 +120,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
{ {
SkipLine(szMe,(const char**)&szMe); SkipLine(szMe,(const char**)&szMe);
if(!PLY::DOM::ParseInstance(szMe,&sPlyDom)) if(!PLY::DOM::ParseInstance(szMe,&sPlyDom))
throw new ImportErrorException( "Invalid .ply file: Unable to build DOM (#1)"); throw DeadlyImportError( "Invalid .ply file: Unable to build DOM (#1)");
} }
else if (!::strncmp(szMe,"binary_",7)) else if (!::strncmp(szMe,"binary_",7))
{ {
@ -138,15 +138,15 @@ void PLYImporter::InternReadFile( const std::string& pFile,
// skip the line, parse the rest of the header and build the DOM // skip the line, parse the rest of the header and build the DOM
SkipLine(szMe,(const char**)&szMe); SkipLine(szMe,(const char**)&szMe);
if(!PLY::DOM::ParseInstanceBinary(szMe,&sPlyDom,bIsBE)) if(!PLY::DOM::ParseInstanceBinary(szMe,&sPlyDom,bIsBE))
throw new ImportErrorException( "Invalid .ply file: Unable to build DOM (#2)"); throw DeadlyImportError( "Invalid .ply file: Unable to build DOM (#2)");
} }
else throw new ImportErrorException( "Invalid .ply file: Unknown file format"); else throw DeadlyImportError( "Invalid .ply file: Unknown file format");
} }
else else
{ {
delete[] this->mBuffer; delete[] this->mBuffer;
AI_DEBUG_INVALIDATE_PTR(this->mBuffer); AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
throw new ImportErrorException( "Invalid .ply file: Missing format specification"); throw DeadlyImportError( "Invalid .ply file: Missing format specification");
} }
this->pcDOM = &sPlyDom; this->pcDOM = &sPlyDom;
@ -155,7 +155,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
this->LoadVertices(&avPositions,false); this->LoadVertices(&avPositions,false);
if (avPositions.empty()) if (avPositions.empty())
throw new ImportErrorException( "Invalid .ply file: No vertices found. " throw DeadlyImportError( "Invalid .ply file: No vertices found. "
"Unable to parse the data format of the PLY file."); "Unable to parse the data format of the PLY file.");
// now load a list of normals. // now load a list of normals.
@ -172,7 +172,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
{ {
if (avPositions.size() < 3) if (avPositions.size() < 3)
{ {
throw new ImportErrorException( "Invalid .ply file: Not enough " throw DeadlyImportError( "Invalid .ply file: Not enough "
"vertices to build a proper face list. "); "vertices to build a proper face list. ");
} }
@ -211,7 +211,7 @@ void PLYImporter::InternReadFile( const std::string& pFile,
&avColors,&avTexCoords,&avMaterials,&avMeshes); &avColors,&avTexCoords,&avMaterials,&avMeshes);
if (avMeshes.empty()) if (avMeshes.empty())
throw new ImportErrorException( "Invalid .ply file: Unable to extract mesh data "); throw DeadlyImportError( "Invalid .ply file: Unable to extract mesh data ");
// now generate the output scene object. Fill the material list // now generate the output scene object. Fill the material list
pScene->mNumMaterials = (unsigned int)avMaterials.size(); pScene->mNumMaterials = (unsigned int)avMaterials.size();

View File

@ -562,7 +562,7 @@ void PretransformVertices::Execute( aiScene* pScene)
// If no meshes are referenced in the node graph it is possible that we get no output meshes. // If no meshes are referenced in the node graph it is possible that we get no output meshes.
if (apcOutMeshes.empty()) { if (apcOutMeshes.empty()) {
throw new ImportErrorException("No output meshes: all meshes are orphaned and are not referenced by nodes"); throw DeadlyImportError("No output meshes: all meshes are orphaned and are not referenced by nodes");
} }
else else
{ {

View File

@ -96,13 +96,13 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
// The header is 22 bytes large // The header is 22 bytes large
if (stream.GetRemainingSize() < 22) if (stream.GetRemainingSize() < 22)
throw new ImportErrorException("File is either empty or corrupt: " + pFile); throw DeadlyImportError("File is either empty or corrupt: " + pFile);
// Check the file's signature // Check the file's signature
if (ASSIMP_strincmp( (const char*)stream.GetPtr(), "quick3Do", 8 ) && if (ASSIMP_strincmp( (const char*)stream.GetPtr(), "quick3Do", 8 ) &&
ASSIMP_strincmp( (const char*)stream.GetPtr(), "quick3Ds", 8 )) ASSIMP_strincmp( (const char*)stream.GetPtr(), "quick3Ds", 8 ))
{ {
throw new ImportErrorException("Not a Quick3D file. Signature string is: " + throw DeadlyImportError("Not a Quick3D file. Signature string is: " +
std::string((const char*)stream.GetPtr(),8)); std::string((const char*)stream.GetPtr(),8));
} }
@ -148,7 +148,7 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
// read all vertices // read all vertices
unsigned int numVerts = (unsigned int)stream.GetI4(); unsigned int numVerts = (unsigned int)stream.GetI4();
if (!numVerts) if (!numVerts)
throw new ImportErrorException("Quick3D: Found mesh with zero vertices"); throw DeadlyImportError("Quick3D: Found mesh with zero vertices");
std::vector<aiVector3D>& verts = mesh.verts; std::vector<aiVector3D>& verts = mesh.verts;
verts.resize(numVerts); verts.resize(numVerts);
@ -163,7 +163,7 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
// read all faces // read all faces
numVerts = (unsigned int)stream.GetI4(); numVerts = (unsigned int)stream.GetI4();
if (!numVerts) if (!numVerts)
throw new ImportErrorException("Quick3D: Found mesh with zero faces"); throw DeadlyImportError("Quick3D: Found mesh with zero faces");
std::vector<Face >& faces = mesh.faces; std::vector<Face >& faces = mesh.faces;
faces.reserve(numVerts); faces.reserve(numVerts);
@ -173,7 +173,7 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
{ {
faces.push_back(Face(stream.GetI2()) ); faces.push_back(Face(stream.GetI2()) );
if (faces.back().indices.empty()) if (faces.back().indices.empty())
throw new ImportErrorException("Quick3D: Found face with zero indices"); throw DeadlyImportError("Quick3D: Found face with zero indices");
} }
// indices // indices
@ -300,7 +300,7 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
tex->mHeight = (unsigned int)stream.GetI4(); tex->mHeight = (unsigned int)stream.GetI4();
if (!tex->mWidth || !tex->mHeight) if (!tex->mWidth || !tex->mHeight)
throw new ImportErrorException("Quick3D: Invalid texture. Width or height is zero"); throw DeadlyImportError("Quick3D: Invalid texture. Width or height is zero");
register unsigned int mul = tex->mWidth * tex->mHeight; register unsigned int mul = tex->mWidth * tex->mHeight;
aiTexel* begin = tex->pcData = new aiTexel[mul]; aiTexel* begin = tex->pcData = new aiTexel[mul];
@ -383,7 +383,7 @@ void Q3DImporter::InternReadFile( const std::string& pFile,
break; break;
default: default:
throw new ImportErrorException("Quick3D: Unknown chunk"); throw DeadlyImportError("Quick3D: Unknown chunk");
break; break;
}; };
} }
@ -391,7 +391,7 @@ outer:
// If we have no mesh loaded - break here // If we have no mesh loaded - break here
if (meshes.empty()) if (meshes.empty())
throw new ImportErrorException("Quick3D: No meshes loaded"); throw DeadlyImportError("Quick3D: No meshes loaded");
// If we have no materials loaded - generate a default mat // If we have no materials loaded - generate a default mat
if (materials.empty()) if (materials.empty())

View File

@ -86,7 +86,7 @@ void RAWImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open RAW file " + pFile + "."); throw DeadlyImportError( "Failed to open RAW file " + pFile + ".");
} }
// allocate storage and copy the contents of the file to a memory buffer // allocate storage and copy the contents of the file to a memory buffer
@ -218,7 +218,7 @@ void RAWImporter::InternReadFile( const std::string& pFile,
if (!pScene->mNumMeshes) if (!pScene->mNumMeshes)
{ {
throw new ImportErrorException("RAW: No meshes loaded. The file seems to be corrupt or empty."); throw DeadlyImportError("RAW: No meshes loaded. The file seems to be corrupt or empty.");
} }
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];

View File

@ -101,7 +101,7 @@ void SMDImporter::InternReadFile(
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open SMD/VTA file " + pFile + "."); throw DeadlyImportError( "Failed to open SMD/VTA file " + pFile + ".");
} }
iFileSize = (unsigned int)file->FileSize(); iFileSize = (unsigned int)file->FileSize();
@ -136,7 +136,7 @@ void SMDImporter::InternReadFile(
{ {
if (asBones.empty()) if (asBones.empty())
{ {
throw new ImportErrorException("SMD: No triangles and no bones have " throw DeadlyImportError("SMD: No triangles and no bones have "
"been found in the file. This file seems to be invalid."); "been found in the file. This file seems to be invalid.");
} }

View File

@ -94,7 +94,7 @@ void STLImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open STL file " + pFile + "."); throw DeadlyImportError( "Failed to open STL file " + pFile + ".");
} }
fileSize = (unsigned int)file->FileSize(); fileSize = (unsigned int)file->FileSize();
@ -276,7 +276,7 @@ void STLImporter::LoadASCIIFile()
if (!curFace) { if (!curFace) {
pMesh->mNumFaces = 0; pMesh->mNumFaces = 0;
throw new ImportErrorException("STL: ASCII file is empty or invalid; no data loaded"); throw DeadlyImportError("STL: ASCII file is empty or invalid; no data loaded");
} }
pMesh->mNumFaces = curFace; pMesh->mNumFaces = curFace;
pMesh->mNumVertices = curFace*3; pMesh->mNumVertices = curFace*3;
@ -289,7 +289,7 @@ bool STLImporter::LoadBinaryFile()
{ {
// skip the first 80 bytes // skip the first 80 bytes
if (fileSize < 84) { if (fileSize < 84) {
throw new ImportErrorException("STL: file is too small for the header"); throw DeadlyImportError("STL: file is too small for the header");
} }
bool bIsMaterialise = false; bool bIsMaterialise = false;
@ -321,11 +321,11 @@ bool STLImporter::LoadBinaryFile()
sz += 4; sz += 4;
if (fileSize < 84 + pMesh->mNumFaces*50) { if (fileSize < 84 + pMesh->mNumFaces*50) {
throw new ImportErrorException("STL: file is too small to hold all facets"); throw DeadlyImportError("STL: file is too small to hold all facets");
} }
if (!pMesh->mNumFaces) { if (!pMesh->mNumFaces) {
throw new ImportErrorException("STL: file is empty. There are no facets defined"); throw DeadlyImportError("STL: file is empty. There are no facets defined");
} }
pMesh->mNumVertices = pMesh->mNumFaces*3; pMesh->mNumVertices = pMesh->mNumFaces*3;

View File

@ -369,7 +369,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene)
if (outMeshes.empty()) if (outMeshes.empty())
{ {
// This should not occur // This should not occur
throw new ImportErrorException("No meshes remaining"); throw DeadlyImportError("No meshes remaining");
} }
// If we added at least one mesh process all nodes in the node // If we added at least one mesh process all nodes in the node

View File

@ -73,13 +73,13 @@ public:
StreamReader(IOStream* _stream) StreamReader(IOStream* _stream)
{ {
if (!_stream) { if (!_stream) {
throw new ImportErrorException("StreamReader: Unable to open file"); throw DeadlyImportError("StreamReader: Unable to open file");
} }
stream = _stream; stream = _stream;
const size_t s = stream->FileSize(); const size_t s = stream->FileSize();
if (!s) { if (!s) {
throw new ImportErrorException("StreamReader: File is empty"); throw DeadlyImportError("StreamReader: File is empty");
} }
current = buffer = new int8_t[s]; current = buffer = new int8_t[s];
@ -181,7 +181,7 @@ public:
void IncPtr(unsigned int plus) { void IncPtr(unsigned int plus) {
current += plus; current += plus;
if (current > end) { if (current > end) {
throw new ImportErrorException("End of file was reached"); throw DeadlyImportError("End of file was reached");
} }
} }
@ -202,7 +202,7 @@ public:
current = p; current = p;
if (current > end || current < buffer) { if (current > end || current < buffer) {
throw new ImportErrorException("End of file was reached"); throw DeadlyImportError("End of file was reached");
} }
} }
@ -240,7 +240,7 @@ public:
limit = buffer + _limit; limit = buffer + _limit;
if (limit > end) { if (limit > end) {
throw new ImportErrorException("StreamReader: Invalid read limit"); throw DeadlyImportError("StreamReader: Invalid read limit");
} }
} }
@ -286,7 +286,7 @@ private:
template <typename T> template <typename T>
T Get() { T Get() {
if (current + sizeof(T) > limit) { if (current + sizeof(T) > limit) {
throw new ImportErrorException("End of file or stream limit was reached"); throw DeadlyImportError("End of file or stream limit was reached");
} }
T f = *((const T*)current); T f = *((const T*)current);

View File

@ -105,19 +105,19 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file == NULL) if( file == NULL)
throw new ImportErrorException( "Failed to open TERRAGEN TERRAIN file " + pFile + "."); throw DeadlyImportError( "Failed to open TERRAGEN TERRAIN file " + pFile + ".");
// Construct a stream reader to read all data in the correct endianess // Construct a stream reader to read all data in the correct endianess
StreamReaderLE reader(file); StreamReaderLE reader(file);
if(reader.GetRemainingSize() < 16) if(reader.GetRemainingSize() < 16)
throw new ImportErrorException( "TER: file is too small" ); throw DeadlyImportError( "TER: file is too small" );
// Check for the existence of the two magic strings 'TERRAGEN' and 'TERRAIN ' // Check for the existence of the two magic strings 'TERRAGEN' and 'TERRAIN '
if (::strncmp((const char*)reader.GetPtr(),AI_TERR_BASE_STRING,8)) if (::strncmp((const char*)reader.GetPtr(),AI_TERR_BASE_STRING,8))
throw new ImportErrorException( "TER: Magic string \'TERRAGEN\' not found" ); throw DeadlyImportError( "TER: Magic string \'TERRAGEN\' not found" );
if (::strncmp((const char*)reader.GetPtr()+8,AI_TERR_TERRAIN_STRING,8)) if (::strncmp((const char*)reader.GetPtr()+8,AI_TERR_TERRAIN_STRING,8))
throw new ImportErrorException( "TER: Magic string \'TERRAIN\' not found" ); throw DeadlyImportError( "TER: Magic string \'TERRAIN\' not found" );
unsigned int x = 0,y = 0,mode = 0; unsigned int x = 0,y = 0,mode = 0;
float rad = 6370.f; float rad = 6370.f;
@ -184,10 +184,10 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
// Ensure we have enough data // Ensure we have enough data
if (reader.GetRemainingSize() < x*y*2) if (reader.GetRemainingSize() < x*y*2)
throw new ImportErrorException("TER: ALTW chunk is too small"); throw DeadlyImportError("TER: ALTW chunk is too small");
if (x <= 1 || y <= 1) if (x <= 1 || y <= 1)
throw new ImportErrorException("TER: Invalid terrain size"); throw DeadlyImportError("TER: Invalid terrain size");
// Allocate the output mesh // Allocate the output mesh
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes = 1]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes = 1];
@ -245,7 +245,7 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
// Check whether we have a mesh now // Check whether we have a mesh now
if (pScene->mNumMeshes != 1) if (pScene->mNumMeshes != 1)
throw new ImportErrorException("TER: Unable to load terrain"); throw DeadlyImportError("TER: Unable to load terrain");
// Set the AI_SCENE_FLAGS_TERRAIN bit // Set the AI_SCENE_FLAGS_TERRAIN bit
pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN; pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN;

View File

@ -117,7 +117,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
// jjjj_a.3d // jjjj_a.3d
pos = pFile.find_last_of('_'); pos = pFile.find_last_of('_');
if (std::string::npos == pos) { if (std::string::npos == pos) {
throw new ImportErrorException("UNREAL: Unexpected naming scheme"); throw DeadlyImportError("UNREAL: Unexpected naming scheme");
} }
extension = pFile.substr(0,pos); extension = pFile.substr(0,pos);
} }
@ -137,14 +137,14 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
// and open the files ... we can't live without them // and open the files ... we can't live without them
IOStream* p = pIOHandler->Open(d_path); IOStream* p = pIOHandler->Open(d_path);
if (!p) if (!p)
throw new ImportErrorException("UNREAL: Unable to open _d file"); throw DeadlyImportError("UNREAL: Unable to open _d file");
StreamReaderLE d_reader(pIOHandler->Open(d_path)); StreamReaderLE d_reader(pIOHandler->Open(d_path));
const uint16_t numTris = d_reader.GetI2(); const uint16_t numTris = d_reader.GetI2();
const uint16_t numVert = d_reader.GetI2(); const uint16_t numVert = d_reader.GetI2();
d_reader.IncPtr(44); d_reader.IncPtr(44);
if (!numTris || numVert < 3) if (!numTris || numVert < 3)
throw new ImportErrorException("UNREAL: Invalid number of vertices/triangles"); throw DeadlyImportError("UNREAL: Invalid number of vertices/triangles");
// maximum texture index // maximum texture index
unsigned int maxTexIdx = 0; unsigned int maxTexIdx = 0;
@ -185,17 +185,17 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
p = pIOHandler->Open(a_path); p = pIOHandler->Open(a_path);
if (!p) if (!p)
throw new ImportErrorException("UNREAL: Unable to open _a file"); throw DeadlyImportError("UNREAL: Unable to open _a file");
StreamReaderLE a_reader(pIOHandler->Open(a_path)); StreamReaderLE a_reader(pIOHandler->Open(a_path));
// read number of frames // read number of frames
const uint32_t numFrames = a_reader.GetI2(); const uint32_t numFrames = a_reader.GetI2();
if (configFrameID >= numFrames) if (configFrameID >= numFrames)
throw new ImportErrorException("UNREAL: The requested frame does not exist"); throw DeadlyImportError("UNREAL: The requested frame does not exist");
uint32_t st = a_reader.GetI2(); uint32_t st = a_reader.GetI2();
if (st != numVert*4) if (st != numVert*4)
throw new ImportErrorException("UNREAL: Unexpected aniv file length"); throw DeadlyImportError("UNREAL: Unexpected aniv file length");
// skip to our frame // skip to our frame
a_reader.IncPtr(configFrameID *numVert*4); a_reader.IncPtr(configFrameID *numVert*4);
@ -328,8 +328,9 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
} }
} }
if (!pScene->mNumMeshes) if (!pScene->mNumMeshes) {
throw new ImportErrorException("UNREAL: Unable to find valid mesh data"); throw DeadlyImportError("UNREAL: Unable to find valid mesh data");
}
// allocate meshes and bind them to the node graph // allocate meshes and bind them to the node graph
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];

View File

@ -89,7 +89,7 @@ AI_WONT_RETURN void ValidateDSProcess::ReportError(const char* msg,...)
#ifdef _DEBUG #ifdef _DEBUG
aiAssert( szBuffer,__LINE__,__FILE__ ); aiAssert( szBuffer,__LINE__,__FILE__ );
#endif #endif
throw new ImportErrorException("Validation failed: " + std::string(szBuffer,iLen)); throw DeadlyImportError("Validation failed: " + std::string(szBuffer,iLen));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void ValidateDSProcess::ReportWarning(const char* msg,...) void ValidateDSProcess::ReportWarning(const char* msg,...)

View File

@ -90,11 +90,11 @@ void XFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, I
// read file into memory // read file into memory
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
if( file.get() == NULL) if( file.get() == NULL)
throw new ImportErrorException( "Failed to open file " + pFile + "."); throw DeadlyImportError( "Failed to open file " + pFile + ".");
size_t fileSize = file->FileSize(); size_t fileSize = file->FileSize();
if( fileSize < 16) if( fileSize < 16)
throw new ImportErrorException( "XFile is too small."); throw DeadlyImportError( "XFile is too small.");
// need to clear members - this method might be called multiple // need to clear members - this method might be called multiple
// times on a single XFileImporter instance. // times on a single XFileImporter instance.
@ -113,7 +113,7 @@ void XFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, I
// if nothing came from it, report it as error // if nothing came from it, report it as error
if( !pScene->mRootNode) if( !pScene->mRootNode)
throw new ImportErrorException( "XFile is ill-formatted - no content imported."); throw DeadlyImportError( "XFile is ill-formatted - no content imported.");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -93,7 +93,7 @@ XFileParser::XFileParser( const std::vector<char>& pBuffer)
// check header // check header
if( strncmp( P, "xof ", 4) != 0) if( strncmp( P, "xof ", 4) != 0)
throw new ImportErrorException( "Header mismatch, file is not an XFile."); throw DeadlyImportError( "Header mismatch, file is not an XFile.");
// read version. It comes in a four byte format such as "0302" // read version. It comes in a four byte format such as "0302"
mMajorVersion = (unsigned int)(P[4] - 48) * 10 + (unsigned int)(P[5] - 48); mMajorVersion = (unsigned int)(P[4] - 48) * 10 + (unsigned int)(P[5] - 48);
@ -140,7 +140,7 @@ XFileParser::XFileParser( const std::vector<char>& pBuffer)
if (compressed) if (compressed)
{ {
#ifdef ASSIMP_BUILD_NO_COMPRESSED_X #ifdef ASSIMP_BUILD_NO_COMPRESSED_X
throw new ImportErrorException("Assimp was built without compressed X support"); throw DeadlyImportError("Assimp was built without compressed X support");
#else #else
/* /////////////////////////////////////////////////////////////////////// /* ///////////////////////////////////////////////////////////////////////
* COMPRESSED X FILE FORMAT * COMPRESSED X FILE FORMAT
@ -185,14 +185,14 @@ XFileParser::XFileParser( const std::vector<char>& pBuffer)
AI_SWAP2(ofs); P1 += 2; AI_SWAP2(ofs); P1 += 2;
if (ofs >= MSZIP_BLOCK) if (ofs >= MSZIP_BLOCK)
throw new ImportErrorException("X: Invalid offset to next MSZIP compressed block"); throw DeadlyImportError("X: Invalid offset to next MSZIP compressed block");
// check magic word // check magic word
uint16_t magic = *((uint16_t*)P1); uint16_t magic = *((uint16_t*)P1);
AI_SWAP2(magic); P1 += 2; AI_SWAP2(magic); P1 += 2;
if (magic != MSZIP_MAGIC) if (magic != MSZIP_MAGIC)
throw new ImportErrorException("X: Unsupported compressed format, expected MSZIP header"); throw DeadlyImportError("X: Unsupported compressed format, expected MSZIP header");
// and advance to the next offset // and advance to the next offset
P1 += ofs; P1 += ofs;
@ -217,7 +217,7 @@ XFileParser::XFileParser( const std::vector<char>& pBuffer)
// and decompress the data .... // and decompress the data ....
int ret = ::inflate( &stream, Z_SYNC_FLUSH ); int ret = ::inflate( &stream, Z_SYNC_FLUSH );
if (ret != Z_OK && ret != Z_STREAM_END) if (ret != Z_OK && ret != Z_STREAM_END)
throw new ImportErrorException("X: Failed to decompress MSZIP-compressed data"); throw DeadlyImportError("X: Failed to decompress MSZIP-compressed data");
::inflateReset( &stream ); ::inflateReset( &stream );
::inflateSetDictionary( &stream, (const Bytef*)out , MSZIP_BLOCK - stream.avail_out ); ::inflateSetDictionary( &stream, (const Bytef*)out , MSZIP_BLOCK - stream.avail_out );
@ -1377,9 +1377,9 @@ aiColor3D XFileParser::ReadRGB()
void XFileParser::ThrowException( const std::string& pText) void XFileParser::ThrowException( const std::string& pText)
{ {
if( mIsBinaryFormat) if( mIsBinaryFormat)
throw new ImportErrorException( pText); throw DeadlyImportError( pText);
else else
throw new ImportErrorException( boost::str( boost::format( "Line %d: %s") % mLineNumber % pText)); throw DeadlyImportError( boost::str( boost::format( "Line %d: %s") % mLineNumber % pText));
} }

View File

@ -55,7 +55,7 @@ namespace Assimp {
* // open the file * // open the file
* boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile)); * boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
* if( file.get() == NULL) { * if( file.get() == NULL) {
* throw new ImportErrorException( "Failed to open file " + pFile + "."); * throw DeadlyImportError( "Failed to open file " + pFile + ".");
* } * }
* *
* // generate a XML reader for it * // generate a XML reader for it

View File

@ -978,7 +978,7 @@ void xxxxImporter::InternReadFile( const std::string& pFile,
// Check whether we can read from the file // Check whether we can read from the file
if( file.get() == NULL) { if( file.get() == NULL) {
throw new ImportErrorException( "Failed to open xxxx file " + pFile + "."); throw DeadlyImportError( "Failed to open xxxx file " + pFile + ".");
} }
// Your task: fill pScene // Your task: fill pScene

View File

@ -81,7 +81,7 @@ void TestPlugin :: GetExtensionList(std::set<std::string>& extensions)
void TestPlugin :: InternReadFile( const std::string& pFile, void TestPlugin :: InternReadFile( const std::string& pFile,
aiScene* pScene, IOSystem* pIOHandler) aiScene* pScene, IOSystem* pIOHandler)
{ {
throw new ImportErrorException(AIUT_DEF_ERROR_TEXT); throw DeadlyImportError(AIUT_DEF_ERROR_TEXT);
} }

View File

@ -2335,6 +2335,10 @@
RelativePath="..\..\code\BaseProcess.h" RelativePath="..\..\code\BaseProcess.h"
> >
</File> </File>
<File
RelativePath="..\..\code\Exceptional.h"
>
</File>
<File <File
RelativePath="..\..\code\Importer.cpp" RelativePath="..\..\code\Importer.cpp"
> >