From db142da571d99a3a44a0eed52a819bc7c4a85617 Mon Sep 17 00:00:00 2001 From: Garux Date: Thu, 29 Apr 2021 19:44:06 +0300 Subject: [PATCH 01/11] orient mdc correctly --- code/AssetLib/MDC/MDCLoader.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/code/AssetLib/MDC/MDCLoader.cpp b/code/AssetLib/MDC/MDCLoader.cpp index 17a349768..c53c31b77 100644 --- a/code/AssetLib/MDC/MDCLoader.cpp +++ b/code/AssetLib/MDC/MDCLoader.cpp @@ -465,6 +465,13 @@ void MDCImporter::InternReadFile( pcMat->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0)); } } + + // 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, + 0.f, 0.f, 1.f, 0.f, + 0.f, -1.f, 0.f, 0.f, + 0.f, 0.f, 0.f, 1.f); } #endif // !! ASSIMP_BUILD_NO_MDC_IMPORTER From 785cca1bb43f9e6047cb566a910fcd0e3d49951f Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:13:10 -0400 Subject: [PATCH 02/11] [amf] Fix crash when file could not be parsed. Fix double free of mXmlParser (deleted but not reset in ParseFile, then deleted again in ~AMFImporter). Should probably use a smart pointer instead, though. Partially addresses https://github.com/assimp/assimp/issues/3888. --- code/AssetLib/AMF/AMFImporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index 1a3efba9a..add1cdb57 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -268,6 +268,7 @@ void AMFImporter::ParseFile(const std::string &pFile, IOSystem *pIOHandler) { mXmlParser = new XmlParser(); if (!mXmlParser->parse(file.get())) { delete mXmlParser; + mXmlParser = nullptr; throw DeadlyImportError("Failed to create XML reader for file" + pFile + "."); } From 116ebf6e10c39fdb2c88b31445b68d51fdfb5c5a Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:30:05 -0400 Subject: [PATCH 03/11] [3ds] Fix assertion failure when file could not be opened Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/3DS/3DSLoader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/3DS/3DSLoader.cpp b/code/AssetLib/3DS/3DSLoader.cpp index a25355ccc..92fe72bbf 100644 --- a/code/AssetLib/3DS/3DSLoader.cpp +++ b/code/AssetLib/3DS/3DSLoader.cpp @@ -143,7 +143,13 @@ void Discreet3DSImporter::SetupProperties(const Importer * /*pImp*/) { // Imports the given file into the given scene structure. void Discreet3DSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - StreamReaderLE theStream(pIOHandler->Open(pFile, "rb")); + + auto theFile = pIOHandler->Open(pFile, "rb"); + if (!theFile) { + throw DeadlyImportError("3DS: Could not open ", pFile); + } + + StreamReaderLE theStream(theFile); // We should have at least one chunk if (theStream.GetRemainingSize() < 16) { From 7f13387487d9650f4212489b86e9a8be4beb2a0f Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:30:29 -0400 Subject: [PATCH 04/11] [cob] Fix assertion failure when file could not be opened. Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/COB/COBLoader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/COB/COBLoader.cpp b/code/AssetLib/COB/COBLoader.cpp index efe7fc446..a6e9d4218 100644 --- a/code/AssetLib/COB/COBLoader.cpp +++ b/code/AssetLib/COB/COBLoader.cpp @@ -137,7 +137,13 @@ void COBImporter::SetupProperties(const Importer * /*pImp*/) { // Imports the given file into the given scene structure. void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { COB::Scene scene; - std::unique_ptr stream(new StreamReaderLE(pIOHandler->Open(pFile, "rb"))); + + auto file = pIOHandler->Open(pFile, "rb"); + if (!file) { + ThrowException("Could not open " + pFile); + } + + std::unique_ptr stream(new StreamReaderLE(file)); // check header char head[32]; From 1cd3752ec6b64d584ebce84c0a6d0ae437a6e5c4 Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:31:06 -0400 Subject: [PATCH 05/11] [ms3d] Fix assertion failure when file could not be opened. Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/MS3D/MS3DLoader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/MS3D/MS3DLoader.cpp b/code/AssetLib/MS3D/MS3DLoader.cpp index 192bcbe41..31cbca83b 100644 --- a/code/AssetLib/MS3D/MS3DLoader.cpp +++ b/code/AssetLib/MS3D/MS3DLoader.cpp @@ -215,7 +215,12 @@ void MS3DImporter :: CollectChildJoints(const std::vector& joints, ai void MS3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { - StreamReaderLE stream(pIOHandler->Open(pFile,"rb")); + + auto file = pIOHandler->Open(pFile, "rb"); + if (!file) + throw DeadlyImportError("MS3D: Could not open ", pFile); + + StreamReaderLE stream(file); // CanRead() should have done this already char head[10]; From e52c2972841afc1806d0f0a7a528cbe4af4fbbf3 Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:31:24 -0400 Subject: [PATCH 06/11] [nendo] Fix assertion failure when file could not be opened. Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/NDO/NDOLoader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/NDO/NDOLoader.cpp b/code/AssetLib/NDO/NDOLoader.cpp index 77fe3e36c..df3a9b15d 100644 --- a/code/AssetLib/NDO/NDOLoader.cpp +++ b/code/AssetLib/NDO/NDOLoader.cpp @@ -116,7 +116,13 @@ void NDOImporter::SetupProperties(const Importer* /*pImp*/) void NDOImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { - StreamReaderBE reader(pIOHandler->Open( pFile, "rb")); + + auto file = pIOHandler->Open( pFile, "rb"); + if (!file) { + throw DeadlyImportError("Nendo: Could not open ", pFile); + } + + StreamReaderBE reader(file); // first 9 bytes are nendo file format ("nendo 1.n") const char* head = (const char*)reader.GetPtr(); From a80b3b25ebba38a04afc8a72ad46c66759b4a640 Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:31:50 -0400 Subject: [PATCH 07/11] [quick3d] Fix assertion failure when file could not be opened. Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/Q3D/Q3DLoader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index b52f86672..710dd52ac 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -106,7 +106,12 @@ const aiImporterDesc *Q3DImporter::GetInfo() const { // Imports the given file into the given scene structure. void Q3DImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - StreamReaderLE stream(pIOHandler->Open(pFile, "rb")); + + auto file = pIOHandler->Open(pFile, "rb"); + if (!file) + throw DeadlyImportError("Quick3D: Could not open ", pFile); + + StreamReaderLE stream(file); // The header is 22 bytes large if (stream.GetRemainingSize() < 22) From 0d3e8b52be6f6c1465fc1ff885fa16f7b221b7d2 Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:32:10 -0400 Subject: [PATCH 08/11] [sib] Fix assertion failure when file could not be opened. Check result of IOSystem::Open before constructing stream. Partially addresses #3888. --- code/AssetLib/SIB/SIBImporter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/SIB/SIBImporter.cpp b/code/AssetLib/SIB/SIBImporter.cpp index 6898fb65c..825f20ee2 100644 --- a/code/AssetLib/SIB/SIBImporter.cpp +++ b/code/AssetLib/SIB/SIBImporter.cpp @@ -804,7 +804,12 @@ static void ReadScene(SIB *sib, StreamReaderLE *stream) { // Imports the given file into the given scene structure. void SIBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - StreamReaderLE stream(pIOHandler->Open(pFile, "rb")); + + auto file = pIOHandler->Open(pFile, "rb"); + if (!file) + throw DeadlyImportError("SIB: Could not open ", pFile); + + StreamReaderLE stream(file); // We should have at least one chunk if (stream.GetRemainingSize() < 16) From 470913bf27e74a6fa6f6ef0f0d0fccd4ebd675de Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:46:24 -0400 Subject: [PATCH 09/11] [assbin] Fail if file could not be opened Fail instead of returning empty scene. Partially addresses #3888. --- code/AssetLib/Assbin/AssbinLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/Assbin/AssbinLoader.cpp b/code/AssetLib/Assbin/AssbinLoader.cpp index d94a9ed7d..d94407e03 100644 --- a/code/AssetLib/Assbin/AssbinLoader.cpp +++ b/code/AssetLib/Assbin/AssbinLoader.cpp @@ -671,7 +671,7 @@ void AssbinImporter::ReadBinaryScene(IOStream *stream, aiScene *scene) { void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { IOStream *stream = pIOHandler->Open(pFile, "rb"); if (nullptr == stream) { - return; + throw DeadlyImportError("ASSBIN: Could not open ", pFile); } // signature From 98f586c8d443d46b14aa551baa00fbb03188903f Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:48:44 -0400 Subject: [PATCH 10/11] [irr] Fail if file could not be parsed. Fail instead of returning empty scene. Partially addresses #3888. TODO: Propagate XML error detail through exception (depends on #3881). --- code/AssetLib/Irr/IRRLoader.cpp | 4 ++-- code/AssetLib/Irr/IRRMeshLoader.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/Irr/IRRLoader.cpp b/code/AssetLib/Irr/IRRLoader.cpp index ed92c93bb..9ec0a9244 100644 --- a/code/AssetLib/Irr/IRRLoader.cpp +++ b/code/AssetLib/Irr/IRRLoader.cpp @@ -859,13 +859,13 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // Check whether we can read from the file if (file.get() == nullptr) { - throw DeadlyImportError("Failed to open IRR file " + pFile); + throw DeadlyImportError("Failed to open IRR file ", pFile); } // Construct the irrXML parser XmlParser st; if (!st.parse( file.get() )) { - return; + throw DeadlyImportError("XML parse error while loading IRR file ", pFile); } pugi::xml_node rootElement = st.getRootNode(); diff --git a/code/AssetLib/Irr/IRRMeshLoader.cpp b/code/AssetLib/Irr/IRRMeshLoader.cpp index edcff6c83..9350e07b8 100644 --- a/code/AssetLib/Irr/IRRMeshLoader.cpp +++ b/code/AssetLib/Irr/IRRMeshLoader.cpp @@ -135,12 +135,12 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, // Check whether we can read from the file if (file.get() == NULL) - throw DeadlyImportError("Failed to open IRRMESH file " + pFile); + throw DeadlyImportError("Failed to open IRRMESH file ", pFile); // Construct the irrXML parser XmlParser parser; if (!parser.parse( file.get() )) { - return; + throw DeadlyImportError("XML parse error while loading IRRMESH file ", pFile); } XmlNode root = parser.getRootNode(); From de5c8ece6f53f5d22ac1c872780cd7518bbb2bb8 Mon Sep 17 00:00:00 2001 From: Jason C Date: Wed, 5 May 2021 17:49:10 -0400 Subject: [PATCH 11/11] [xgl] Fail if file could not be parsed. Fail instead of returning empty scene. Partially addresses #3888. TODO: Propagate XML error detail through exception (depends on #3881). --- code/AssetLib/XGL/XGLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/XGL/XGLLoader.cpp b/code/AssetLib/XGL/XGLLoader.cpp index 00e8bafb2..3b84d7ba9 100644 --- a/code/AssetLib/XGL/XGLLoader.cpp +++ b/code/AssetLib/XGL/XGLLoader.cpp @@ -200,7 +200,7 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // parse the XML file mXmlParser = new XmlParser; if (!mXmlParser->parse(stream.get())) { - return; + throw DeadlyImportError("XML parse error while loading XGL file ", pFile); } TempScope scope;