|
@@ -482,37 +482,43 @@ bool Importer::ValidateFlags(unsigned int pFlags) const {
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
|
|
- size_t pLength,
|
|
|
- unsigned int pFlags,
|
|
|
- const char* pHint /*= ""*/) {
|
|
|
+const aiScene* Importer::ReadFileFromMemory(const void* pBuffer, size_t pLength, unsigned int pFlags, const char* pHint ) {
|
|
|
ai_assert(nullptr != pimpl);
|
|
|
|
|
|
- ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
- if (!pHint) {
|
|
|
- pHint = "";
|
|
|
- }
|
|
|
-
|
|
|
- if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
|
|
|
- pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
|
|
|
- return nullptr;
|
|
|
- }
|
|
|
-
|
|
|
- // prevent deletion of the previous IOHandler
|
|
|
IOSystem* io = pimpl->mIOHandler;
|
|
|
- pimpl->mIOHandler = nullptr;
|
|
|
-
|
|
|
- SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
|
|
|
-
|
|
|
- // read the file and recover the previous IOSystem
|
|
|
- static const size_t BufSize(Importer::MaxLenHint + 28);
|
|
|
- char fbuff[BufSize];
|
|
|
- ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
|
|
|
+ try {
|
|
|
+ if (pHint == nullptr) {
|
|
|
+ pHint = "";
|
|
|
+ }
|
|
|
+ if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
|
|
|
+ pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ // prevent deletion of the previous IOHandler
|
|
|
+ pimpl->mIOHandler = nullptr;
|
|
|
+
|
|
|
+ SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
|
|
|
+
|
|
|
+ // read the file and recover the previous IOSystem
|
|
|
+ static const size_t BufSize(Importer::MaxLenHint + 28);
|
|
|
+ char fbuff[BufSize];
|
|
|
+ ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
|
|
|
+
|
|
|
+ ReadFile(fbuff,pFlags);
|
|
|
+ SetIOHandler(io);
|
|
|
+ } catch(const DeadlyImportError &e) {
|
|
|
+ pimpl->mErrorString = e.what();
|
|
|
+ pimpl->mException = std::current_exception();
|
|
|
+ SetIOHandler(io);
|
|
|
+ return ExceptionSwallower<const aiScene*>()(); \
|
|
|
+ } catch(...) {
|
|
|
+ pimpl->mErrorString = "Unknown exception";
|
|
|
+ pimpl->mException = std::current_exception();
|
|
|
+ SetIOHandler(io);
|
|
|
+ return ExceptionSwallower<const aiScene*>()(); \
|
|
|
|
|
|
- ReadFile(fbuff,pFlags);
|
|
|
- SetIOHandler(io);
|
|
|
+ }
|
|
|
|
|
|
- ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mException);
|
|
|
return pimpl->mScene;
|
|
|
}
|
|
|
|