------------------------------------------------------------------------------------------------
| 483 | |
| 484 | // ------------------------------------------------------------------------------------------------ |
| 485 | const aiScene* Importer::ReadFileFromMemory(const void* pBuffer, size_t pLength, unsigned int pFlags, const char* pHint ) { |
| 486 | ai_assert(nullptr != pimpl); |
| 487 | |
| 488 | IOSystem* io = pimpl->mIOHandler; |
| 489 | try { |
| 490 | if (pHint == nullptr) { |
| 491 | pHint = ""; |
| 492 | } |
| 493 | if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) { |
| 494 | pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()"; |
| 495 | return nullptr; |
| 496 | } |
| 497 | // prevent deletion of the previous IOHandler |
| 498 | pimpl->mIOHandler = nullptr; |
| 499 | |
| 500 | SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io)); |
| 501 | |
| 502 | // read the file and recover the previous IOSystem |
| 503 | static const size_t BufSize(Importer::MaxLenHint + 28); |
| 504 | char fbuff[BufSize]; |
| 505 | ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint); |
| 506 | |
| 507 | ReadFile(fbuff,pFlags); |
| 508 | SetIOHandler(io); |
| 509 | } catch(const DeadlyImportError &e) { |
| 510 | pimpl->mErrorString = e.what(); |
| 511 | pimpl->mException = std::current_exception(); |
| 512 | SetIOHandler(io); |
| 513 | return ExceptionSwallower<const aiScene*>()(); \ |
| 514 | } catch(...) { |
| 515 | pimpl->mErrorString = "Unknown exception"; |
| 516 | pimpl->mException = std::current_exception(); |
| 517 | SetIOHandler(io); |
| 518 | return ExceptionSwallower<const aiScene*>()(); \ |
| 519 | |
| 520 | } |
| 521 | |
| 522 | return pimpl->mScene; |
| 523 | } |
| 524 | |
| 525 | // ------------------------------------------------------------------------------------------------ |
| 526 | void WriteLogOpening(const std::string& file) { |
no test coverage detected