From 40d882af4f1f9633de336ae225dd6d368da05ff2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 16 Jan 2020 20:25:47 +0100 Subject: [PATCH] fix irrreader leak. --- code/3DS/3DSConverter.cpp | 2 - code/3DS/3DSHelper.h | 4 +- code/3DS/3DSLoader.cpp | 16 ++--- code/3DS/3DSLoader.h | 6 +- code/Assjson/cencode.c | 4 ++ code/CSM/CSMLoader.cpp | 2 +- code/FBX/FBXConverter.cpp | 4 +- code/Irr/IRRLoader.cpp | 1 + code/Material/MaterialSystem.cpp | 2 +- code/Q3BSP/Q3BSPFileImporter.cpp | 2 +- code/SMD/SMDLoader.cpp | 2 +- code/Unreal/UnrealLoader.cpp | 98 +++++++++++++++++++++++++-- code/Unreal/UnrealLoader.h | 110 ++----------------------------- contrib/zip/src/miniz.h | 2 +- tools/assimp_view/Display.cpp | 2 +- tools/assimp_view/Material.cpp | 16 ++--- 16 files changed, 126 insertions(+), 147 deletions(-) diff --git a/code/3DS/3DSConverter.cpp b/code/3DS/3DSConverter.cpp index 3c3da36a3..e1bb16c27 100644 --- a/code/3DS/3DSConverter.cpp +++ b/code/3DS/3DSConverter.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2019, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/code/3DS/3DSHelper.h b/code/3DS/3DSHelper.h index 8eb4cd97c..bdb8615a4 100644 --- a/code/3DS/3DSHelper.h +++ b/code/3DS/3DSHelper.h @@ -55,8 +55,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include //sprintf -namespace Assimp { -namespace D3DS { +namespace Assimp { +namespace D3DS { #include diff --git a/code/3DS/3DSLoader.cpp b/code/3DS/3DSLoader.cpp index 3c659d0b0..ed3ab8bc3 100644 --- a/code/3DS/3DSLoader.cpp +++ b/code/3DS/3DSLoader.cpp @@ -72,7 +72,6 @@ static const aiImporterDesc desc = { "3ds prj" }; - // ------------------------------------------------------------------------------------------------ // Begins a new parsing block // - Reads the current chunk and validates it @@ -141,23 +140,19 @@ bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandle // ------------------------------------------------------------------------------------------------ // Loader registry entry -const aiImporterDesc* Discreet3DSImporter::GetInfo () const -{ +const aiImporterDesc* Discreet3DSImporter::GetInfo () const { return &desc; } // ------------------------------------------------------------------------------------------------ // Setup configuration properties -void Discreet3DSImporter::SetupProperties(const Importer* /*pImp*/) -{ +void Discreet3DSImporter::SetupProperties(const Importer* /*pImp*/) { // nothing to be done for the moment } // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void Discreet3DSImporter::InternReadFile( const std::string& pFile, - aiScene* pScene, IOSystem* pIOHandler) -{ +void Discreet3DSImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { StreamReaderLE stream(pIOHandler->Open(pFile,"rb")); // We should have at least one chunk @@ -200,7 +195,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile, ComputeNormalsWithSmoothingsGroups(mesh); } - // Replace all occurences of the default material with a + // Replace all occurrences of the default material with a // valid material. Generate it if no material containing // DEFAULT in its name has been found in the file ReplaceDefaultMaterial(); @@ -227,8 +222,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile, // ------------------------------------------------------------------------------------------------ // Applies a master-scaling factor to the imported scene -void Discreet3DSImporter::ApplyMasterScale(aiScene* pScene) -{ +void Discreet3DSImporter::ApplyMasterScale(aiScene* pScene) { // There are some 3DS files with a zero scaling factor if (!mMasterScale)mMasterScale = 1.0f; else mMasterScale = 1.0f / mMasterScale; diff --git a/code/3DS/3DSLoader.h b/code/3DS/3DSLoader.h index f57e6a8e3..99e6d549b 100644 --- a/code/3DS/3DSLoader.h +++ b/code/3DS/3DSLoader.h @@ -65,15 +65,11 @@ using namespace D3DS; // --------------------------------------------------------------------------------- /** Importer class for 3D Studio r3 and r4 3DS files */ -class Discreet3DSImporter : public BaseImporter -{ +class Discreet3DSImporter : public BaseImporter { public: - Discreet3DSImporter(); ~Discreet3DSImporter(); -public: - // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. * See BaseImporter::CanRead() for details. diff --git a/code/Assjson/cencode.c b/code/Assjson/cencode.c index db99e7efa..707d31624 100644 --- a/code/Assjson/cencode.c +++ b/code/Assjson/cencode.c @@ -9,6 +9,9 @@ For details, see http://sourceforge.net/projects/libb64 const int CHARS_PER_LINE = 72; +#pragma warning(push) +#pragma warning(disable : 4244) + void base64_init_encodestate(base64_encodestate* state_in) { state_in->step = step_A; @@ -107,3 +110,4 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in) return codechar - code_out; } +#pragma warning(pop) diff --git a/code/CSM/CSMLoader.cpp b/code/CSM/CSMLoader.cpp index 9dbb38467..b91ef096a 100644 --- a/code/CSM/CSMLoader.cpp +++ b/code/CSM/CSMLoader.cpp @@ -178,7 +178,7 @@ void CSMImporter::InternReadFile( const std::string& pFile, *ot++ = *buffer++; *ot = '\0'; - nda->mNodeName.length = (size_t)(ot-nda->mNodeName.data); + nda->mNodeName.length = static_cast(ot-nda->mNodeName.data); } anim->mNumChannels = static_cast(anims_temp.size()); diff --git a/code/FBX/FBXConverter.cpp b/code/FBX/FBXConverter.cpp index 5b34868ba..965b12d1d 100644 --- a/code/FBX/FBXConverter.cpp +++ b/code/FBX/FBXConverter.cpp @@ -1564,8 +1564,10 @@ namespace Assimp { bone_map.clear(); } - catch (std::exception&e) { + catch (std::exception &e) { + FBXImporter::LogError(e.what()); std::for_each(bones.begin(), bones.end(), Util::delete_fun()); + throw; } diff --git a/code/Irr/IRRLoader.cpp b/code/Irr/IRRLoader.cpp index e94fd85a4..f17ce6958 100644 --- a/code/Irr/IRRLoader.cpp +++ b/code/Irr/IRRLoader.cpp @@ -1483,6 +1483,7 @@ void IRRImporter::InternReadFile( const std::string& pFile, */ delete root; + delete reader; } #endif // !! ASSIMP_BUILD_NO_IRR_IMPORTER diff --git a/code/Material/MaterialSystem.cpp b/code/Material/MaterialSystem.cpp index aa3df9ac2..479e8c297 100644 --- a/code/Material/MaterialSystem.cpp +++ b/code/Material/MaterialSystem.cpp @@ -504,7 +504,7 @@ aiReturn aiMaterial::AddBinaryProperty (const void* pInput, pcNew->mData = new char[pSizeInBytes]; memcpy (pcNew->mData,pInput,pSizeInBytes); - pcNew->mKey.length = ::strlen(pKey); + pcNew->mKey.length = static_cast( ::strlen(pKey) ); ai_assert ( MAXLEN > pcNew->mKey.length); strcpy( pcNew->mKey.data, pKey ); diff --git a/code/Q3BSP/Q3BSPFileImporter.cpp b/code/Q3BSP/Q3BSPFileImporter.cpp index 4add00a07..ba08fe62c 100644 --- a/code/Q3BSP/Q3BSPFileImporter.cpp +++ b/code/Q3BSP/Q3BSPFileImporter.cpp @@ -616,7 +616,7 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *model // We'll leave it up to the user to figure out which extension the file has. aiString name; strncpy( name.data, pTexture->strName, sizeof name.data ); - name.length = strlen( name.data ); + name.length = static_cast(strlen( name.data )); pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); } } diff --git a/code/SMD/SMDLoader.cpp b/code/SMD/SMDLoader.cpp index 7eb6b18d1..4ca72345f 100644 --- a/code/SMD/SMDLoader.cpp +++ b/code/SMD/SMDLoader.cpp @@ -616,7 +616,7 @@ void SMDImporter::CreateOutputMaterials() { if (aszTextures[iMat].length()) { ::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1); - szName.length = aszTextures[iMat].length(); + szName.length = static_cast( aszTextures[iMat].length() ); pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0)); } } diff --git a/code/Unreal/UnrealLoader.cpp b/code/Unreal/UnrealLoader.cpp index 0bd4650d0..31bfb480b 100644 --- a/code/Unreal/UnrealLoader.cpp +++ b/code/Unreal/UnrealLoader.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2019, assimp team - - +Copyright (c) 2006-2020, assimp team All rights reserved. @@ -48,8 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * http://local.wasp.uwa.edu.au/~pbourke/dataformats/unreal/ */ - - #ifndef ASSIMP_BUILD_NO_3D_IMPORTER #include "Unreal/UnrealLoader.h" @@ -65,9 +61,99 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include using namespace Assimp; +namespace Unreal { + + /* + 0 = Normal one-sided + 1 = Normal two-sided + 2 = Translucent two-sided + 3 = Masked two-sided + 4 = Modulation blended two-sided + 8 = Placeholder triangle for weapon positioning (invisible) + */ +enum MeshFlags { + MF_NORMAL_OS = 0, + MF_NORMAL_TS = 1, + MF_NORMAL_TRANS_TS = 2, + MF_NORMAL_MASKED_TS = 3, + MF_NORMAL_MOD_TS = 4, + MF_WEAPON_PLACEHOLDER = 8 +}; + +// a single triangle +struct Triangle { + uint16_t mVertex[3]; // Vertex indices + char mType; // James' Mesh Type + char mColor; // Color for flat and Gourand Shaded + unsigned char mTex[3][2]; // Texture UV coordinates + unsigned char mTextureNum; // Source texture offset + char mFlags; // Unreal Mesh Flags (unused) + + unsigned int matIndex; +}; + +// temporary representation for a material +struct TempMat { + TempMat() : + type(), tex(), numFaces(0) {} + + explicit TempMat(const Triangle &in) : + type((Unreal::MeshFlags)in.mType), tex(in.mTextureNum), numFaces(0) {} + + // type of mesh + Unreal::MeshFlags type; + + // index of texture + unsigned int tex; + + // number of faces using us + unsigned int numFaces; + + // for std::find + bool operator==(const TempMat &o) { + return (tex == o.tex && type == o.type); + } +}; + +struct Vertex { + int32_t X : 11; + int32_t Y : 11; + int32_t Z : 10; +}; + +// UNREAL vertex compression +inline void CompressVertex(const aiVector3D &v, uint32_t &out) { + union { + Vertex n; + int32_t t; + }; + n.X = (int32_t)v.x; + n.Y = (int32_t)v.y; + n.Z = (int32_t)v.z; + ::memcpy(&out, &t, sizeof(int32_t)); + //out = t; +} + +// UNREAL vertex decompression +inline void DecompressVertex(aiVector3D &v, int32_t in) { + union { + Vertex n; + int32_t i; + }; + i = in; + + v.x = (float)n.X; + v.y = (float)n.Y; + v.z = (float)n.Z; +} + +} // end namespace Unreal + + static const aiImporterDesc desc = { "Unreal Mesh Importer", "", @@ -403,7 +489,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile, // set color and name mat->AddProperty(&color,1,AI_MATKEY_COLOR_DIFFUSE); - s.length = ::strlen(s.data); + s.length = static_cast(::strlen(s.data)); mat->AddProperty(&s,AI_MATKEY_NAME); // set texture, if any diff --git a/code/Unreal/UnrealLoader.h b/code/Unreal/UnrealLoader.h index 678aaa76b..e758e815a 100644 --- a/code/Unreal/UnrealLoader.h +++ b/code/Unreal/UnrealLoader.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2019, assimp team - +Copyright (c) 2006-2020, assimp team All rights reserved. @@ -47,118 +46,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define INCLUDED_AI_3D_LOADER_H #include -#include -namespace Assimp { -namespace Unreal { - - /* - 0 = Normal one-sided - 1 = Normal two-sided - 2 = Translucent two-sided - 3 = Masked two-sided - 4 = Modulation blended two-sided - 8 = Placeholder triangle for weapon positioning (invisible) - */ -enum MeshFlags { - MF_NORMAL_OS = 0, - MF_NORMAL_TS = 1, - MF_NORMAL_TRANS_TS = 2, - MF_NORMAL_MASKED_TS = 3, - MF_NORMAL_MOD_TS = 4, - MF_WEAPON_PLACEHOLDER = 8 -}; - - // a single triangle -struct Triangle { - uint16_t mVertex[3]; // Vertex indices - char mType; // James' Mesh Type - char mColor; // Color for flat and Gourand Shaded - unsigned char mTex[3][2]; // Texture UV coordinates - unsigned char mTextureNum; // Source texture offset - char mFlags; // Unreal Mesh Flags (unused) - - unsigned int matIndex; -}; - -// temporary representation for a material -struct TempMat { - TempMat() - : type() - , tex() - , numFaces (0) - {} - - explicit TempMat(const Triangle& in) - : type ((Unreal::MeshFlags)in.mType) - , tex (in.mTextureNum) - , numFaces (0) - {} - - // type of mesh - Unreal::MeshFlags type; - - // index of texture - unsigned int tex; - - // number of faces using us - unsigned int numFaces; - - // for std::find - bool operator == (const TempMat& o ) { - return (tex == o.tex && type == o.type); - } -}; - -struct Vertex -{ - int32_t X : 11; - int32_t Y : 11; - int32_t Z : 10; -}; - - // UNREAL vertex compression -inline void CompressVertex(const aiVector3D& v, uint32_t& out) -{ - union { - Vertex n; - int32_t t; - }; - n.X = (int32_t)v.x; - n.Y = (int32_t)v.y; - n.Z = (int32_t)v.z; - ::memcpy( &out, &t, sizeof(int32_t)); - //out = t; -} - - // UNREAL vertex decompression -inline void DecompressVertex(aiVector3D& v, int32_t in) -{ - union { - Vertex n; - int32_t i; - }; - i = in; - - v.x = (float)n.X; - v.y = (float)n.Y; - v.z = (float)n.Z; -} - -} // end namespace Unreal +namespace Assimp { // --------------------------------------------------------------------------- /** @brief Importer class to load UNREAL files (*.3d) */ -class UnrealImporter : public BaseImporter -{ +class UnrealImporter : public BaseImporter { public: UnrealImporter(); ~UnrealImporter(); - -public: - // ------------------------------------------------------------------- /** @brief Returns whether we can handle the format of the given file * @@ -184,7 +82,6 @@ protected: */ void SetupProperties(const Importer* pImp); - // ------------------------------------------------------------------- /** @brief Imports the given file into the given scene structure. * @@ -204,4 +101,5 @@ private: }; // !class UnrealImporter } // end of namespace Assimp + #endif // AI_UNREALIMPORTER_H_INC diff --git a/contrib/zip/src/miniz.h b/contrib/zip/src/miniz.h index c4fcfb83e..07f7b2de2 100644 --- a/contrib/zip/src/miniz.h +++ b/contrib/zip/src/miniz.h @@ -6085,7 +6085,7 @@ mz_zip_writer_compute_padding_needed_for_file_alignment(mz_zip_archive *pZip) { if (!pZip->m_file_offset_alignment) return 0; n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1)); - return (pZip->m_file_offset_alignment - n) & + return (mz_uint)(pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1); } diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index ab29c1d3e..9105cf97a 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -275,7 +275,7 @@ int CDisplay::ReplaceCurrentTexture(const char* szPath) IDirect3DTexture9* piTexture = NULL; aiString szString; strcpy(szString.data,szPath); - szString.length = strlen(szPath); + szString.length = static_cast(strlen(szPath)); CMaterialManager::Instance().LoadTexture(&piTexture,&szString); if (!piTexture) { diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index 2c5316d81..ef32691d4 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -287,7 +287,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString) size_t iLen2 = iLen+1; iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; memcpy(p_szString->data,szTempB,iLen2); - p_szString->length = iLen; + p_szString->length = static_cast(iLen); return true; } } @@ -301,7 +301,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString) size_t iLen2 = iLen+1; iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; memcpy(p_szString->data,szTempB,iLen2); - p_szString->length = iLen; + p_szString->length = static_cast(iLen); return true; } } @@ -392,7 +392,7 @@ int CMaterialManager::FindValidPath(aiString* p_szString) if((pFile=fopen( tmp2,"r" ))){ fclose( pFile ); strcpy(p_szString->data,tmp2); - p_szString->length = strlen(tmp2); + p_szString->length = static_cast(strlen(tmp2)); return 1; } } @@ -403,11 +403,11 @@ int CMaterialManager::FindValidPath(aiString* p_szString) fclose(pFile); // copy the result string back to the aiString - const size_t iLen = strlen(szTemp); - size_t iLen2 = iLen+1; - iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; - memcpy(p_szString->data,szTemp,iLen2); - p_szString->length = iLen; + const size_t len = strlen(szTemp); + size_t len2 = len+1; + len2 = len2 > MAXLEN ? MAXLEN : len2; + memcpy(p_szString->data, szTemp, len2); + p_szString->length = static_cast(len); } return 1;