diff --git a/code/Importer.cpp b/code/Importer.cpp index eb9f13c92..8c3534d49 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -45,19 +45,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssimpPCH.h" -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ /* Uncomment this line to prevent Assimp from catching unknown exceptions. * - * Note that any Exception except ImportErrorException may lead to + * Note that any Exception except DeadlyImportError may lead to * undefined behaviour -> loaders could remain in an unusable state and * further imports with the same Importer instance could fail/crash/burn ... */ -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ #define ASSIMP_CATCH_GLOBAL_EXCEPTIONS -// ....................................................................................... + +// ------------------------------------------------------------------------------------------------ // Internal headers -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ #include "BaseImporter.h" #include "BaseProcess.h" #include "DefaultIOStream.h" @@ -67,10 +68,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ScenePreprocessor.h" #include "MemoryIOWrapper.h" -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ // Importers // (include_new_importers_here) -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ #ifndef AI_BUILD_NO_X_IMPORTER # include "XFileImporter.h" #endif @@ -168,9 +169,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # include "COBLoader.h" #endif -// ....................................................................................... -// PostProcess-Steps -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ +// Post processing-Steps +// ------------------------------------------------------------------------------------------------ #ifndef AI_BUILD_NO_CALCTANGENTS_PROCESS # include "CalcTangentsProcess.h" #endif @@ -241,15 +242,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; using namespace Assimp::Intern; -// ....................................................................................... +// ------------------------------------------------------------------------------------------------ // Intern::AllocateFromAssimpHeap serves as abstract base class. It overrides // new and delete (and their array counterparts) of public API classes (e.g. Logger) to -// utilize our DLL heap -// ....................................................................................... +// utilize our DLL heap. +// See http://www.gotw.ca/publications/mill15.htm +// ------------------------------------------------------------------------------------------------ void* AllocateFromAssimpHeap::operator new ( size_t num_bytes) { return ::operator new(num_bytes); } +void* AllocateFromAssimpHeap::operator new ( size_t num_bytes, const std::nothrow_t& ) { + try { + return AllocateFromAssimpHeap::operator new( num_bytes ); + } + catch( ... ) { + return NULL; + } +} + void AllocateFromAssimpHeap::operator delete ( void* data) { return ::operator delete(data); } @@ -258,6 +269,15 @@ void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes) { return ::operator new[](num_bytes); } +void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes, const std::nothrow_t& ) { + try { + return AllocateFromAssimpHeap::operator new[]( num_bytes ); + } + catch( ... ) { + return NULL; + } +} + void AllocateFromAssimpHeap::operator delete[] ( void* data) { return ::operator delete[](data); } diff --git a/include/aiTypes.h b/include/aiTypes.h index d7a3852f3..4a49a179b 100644 --- a/include/aiTypes.h +++ b/include/aiTypes.h @@ -63,10 +63,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "aiQuaternion.h" #ifdef __cplusplus -# include // for aiString::Set(const std::string&) +#include // for std::nothrow_t +#include // for aiString::Set(const std::string&) namespace Assimp { - //! @cond never namespace Intern { // -------------------------------------------------------------------- @@ -83,13 +83,16 @@ namespace Intern { */ // -------------------------------------------------------------------- struct ASSIMP_API AllocateFromAssimpHeap { + // http://www.gotw.ca/publications/mill15.htm // new/delete overload - void *operator new ( size_t num_bytes); + void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */; + void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw(); void operator delete ( void* data); // array new/delete overload - void *operator new[] ( size_t num_bytes); + void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */; + void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw(); void operator delete[] ( void* data); }; // struct AllocateFromAssimpHeap