From 6aafc5879761c41e950df16355782ab7ab801f36 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 15:51:20 +0200 Subject: [PATCH 01/11] Add missing assignment operator to aiString --- include/assimp/types.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/assimp/types.h b/include/assimp/types.h index f0d9b2428..9868f657c 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -304,6 +304,20 @@ struct aiString data[len] = 0; } + + /** Assigment operator */ + aiString& operator = (const aiString &rOther) { + if (this == &rOther) { + return *this; + } + + length = rOther.length;; + memcpy( data, rOther.data, length); + data[length] = '\0'; + return *this; + } + + /** Assign a const char* to the string */ aiString& operator = (const char* sz) { Set(sz); From a64d5155051a72cf4442af75facc4d71c22085a4 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 16:04:14 +0200 Subject: [PATCH 02/11] Fix varible shadowing issue --- include/assimp/matrix3x3.inl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/assimp/matrix3x3.inl b/include/assimp/matrix3x3.inl index aaf62eb0f..ab2cc410b 100644 --- a/include/assimp/matrix3x3.inl +++ b/include/assimp/matrix3x3.inl @@ -313,16 +313,16 @@ inline aiMatrix3x3t& aiMatrix3x3t::FromToMatrix(const aiVector3t(2.0) / (u * u); - const TReal c2 = static_cast(2.0) / (v * v); - const TReal c3 = c1 * c2 * (u * v); + const TReal c1_ = static_cast(2.0) / (u * u); + const TReal c2_ = static_cast(2.0) / (v * v); + const TReal c3_ = c1_ * c2_ * (u * v); for (unsigned int i = 0; i < 3; i++) { for (unsigned int j = 0; j < 3; j++) { - mtx[i][j] = - c1 * u[i] * u[j] - c2 * v[i] * v[j] - + c3 * v[i] * u[j]; + mtx[i][j] = - c1_ * u[i] * u[j] - c2_ * v[i] * v[j] + + c3_ * v[i] * u[j]; } mtx[i][i] += static_cast(1.0); } From 82980c8a9cd604e59a04251d74e8b8caa4ad401c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 16:24:45 +0200 Subject: [PATCH 03/11] Add missing assignment operator to aiBone --- include/assimp/mesh.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/assimp/mesh.h b/include/assimp/mesh.h index a532e2b46..ea27d03a1 100644 --- a/include/assimp/mesh.h +++ b/include/assimp/mesh.h @@ -270,6 +270,32 @@ struct aiBone } } + + //! Assignment operator + aiBone &operator=(const aiBone& other) + { + if (this == &other) { + return *this; + } + + mName = other.mName; + mNumWeights = other.mNumWeights; + mOffsetMatrix = other.mOffsetMatrix; + + if (other.mWeights && other.mNumWeights) + { + if (mWeights) { + delete[] mWeights; + } + + mWeights = new aiVertexWeight[mNumWeights]; + ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight)); + } + + return *this; + } + + //! Destructor - deletes the array of vertex weights ~aiBone() { From b0b125dfe6fd24b5c63db1eb5ac1d9b2afc34a6e Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 16:34:40 +0200 Subject: [PATCH 04/11] Initialize all members of aiVertexWeight in constructor --- include/assimp/mesh.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/assimp/mesh.h b/include/assimp/mesh.h index ea27d03a1..5896284f6 100644 --- a/include/assimp/mesh.h +++ b/include/assimp/mesh.h @@ -212,7 +212,10 @@ struct aiVertexWeight #ifdef __cplusplus //! Default constructor - aiVertexWeight() { } + aiVertexWeight() + : mVertexId(0) + , mWeight(0.0f) + { } //! Initialisation from a given index and vertex weight factor //! \param pID ID From e21b79a8bf2fdfc70f8f4195b6aae3a5d9f34c8c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 16:45:07 +0200 Subject: [PATCH 05/11] Mark Importer assignment operator deleted --- include/assimp/Importer.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index 1263868bc..9ae8fccc6 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -139,6 +139,11 @@ public: */ Importer(const Importer& other); + // ------------------------------------------------------------------- + /** Assignment operator has been deleted + */ + Importer &operator=(const Importer &) = delete; + // ------------------------------------------------------------------- /** Destructor. The object kept ownership of the imported data, * which now will be destroyed along with the object. From 123b9ca71a299741f5addaa9752c3dbca3053712 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 16:54:19 +0200 Subject: [PATCH 06/11] Initialize all members of aiMeshKey in constructor --- include/assimp/anim.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/assimp/anim.h b/include/assimp/anim.h index 9156aac06..1a2c11044 100644 --- a/include/assimp/anim.h +++ b/include/assimp/anim.h @@ -162,7 +162,10 @@ struct aiMeshKey #ifdef __cplusplus - aiMeshKey() { + aiMeshKey() + : mTime(0.0) + , mValue(0) + { } /** Construction from a given time and key value */ From 9397932e4f10d83954d5a4af0b0bd10a1b2894e6 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 17:08:25 +0200 Subject: [PATCH 07/11] PretransformVertices: Rearrange some assignments to clarify things --- code/PretransformVertices.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 6c569c185..cc5c669e4 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -651,7 +651,8 @@ void PretransformVertices::Execute( aiScene* pScene) // generate mesh nodes for (unsigned int i = 0; i < pScene->mNumMeshes;++i,++nodes) { - aiNode* pcNode = *nodes = new aiNode(); + aiNode* pcNode = new aiNode(); + *nodes = pcNode; pcNode->mParent = pScene->mRootNode; pcNode->mName = pScene->mMeshes[i]->mName; @@ -663,7 +664,8 @@ void PretransformVertices::Execute( aiScene* pScene) // generate light nodes for (unsigned int i = 0; i < pScene->mNumLights;++i,++nodes) { - aiNode* pcNode = *nodes = new aiNode(); + aiNode* pcNode = new aiNode(); + *nodes = pcNode; pcNode->mParent = pScene->mRootNode; pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "light_%u",i); pScene->mLights[i]->mName = pcNode->mName; @@ -671,7 +673,8 @@ void PretransformVertices::Execute( aiScene* pScene) // generate camera nodes for (unsigned int i = 0; i < pScene->mNumCameras;++i,++nodes) { - aiNode* pcNode = *nodes = new aiNode(); + aiNode* pcNode = new aiNode(); + *nodes = pcNode; pcNode->mParent = pScene->mRootNode; pcNode->mName.length = ::ai_snprintf(pcNode->mName.data,MAXLEN,"cam_%u",i); pScene->mCameras[i]->mName = pcNode->mName; From be865ae61380068fadd7e48f6ccc7d39287a46e8 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 17:19:27 +0200 Subject: [PATCH 08/11] LimitBoneWeightsProcess: Initialize all members of Weight in constructor --- code/LimitBoneWeightsProcess.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/LimitBoneWeightsProcess.h b/code/LimitBoneWeightsProcess.h index 2fc6e02b1..090181982 100644 --- a/code/LimitBoneWeightsProcess.h +++ b/code/LimitBoneWeightsProcess.h @@ -120,7 +120,11 @@ public: { unsigned int mBone; ///< Index of the bone float mWeight; ///< Weight of that bone on this vertex - Weight() { } + Weight() + : mBone(0) + , mWeight(0.0f) + { } + Weight( unsigned int pBone, float pWeight) { mBone = pBone; From da19ed0b2a7a5e212bd1d843ded29bfc3412ccb7 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 17:25:31 +0200 Subject: [PATCH 09/11] BaseImporter: Remove dead condition operator new never returns NULL, it throws exception on allocation failure --- code/BaseImporter.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index f653d8d81..0892efd9f 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -157,9 +157,6 @@ void BaseImporter::GetExtensionList(std::set& extensions) // read 200 characters from the file std::unique_ptr _buffer (new char[searchBytes+1 /* for the '\0' */]); char* buffer = _buffer.get(); - if( NULL == buffer ) { - return false; - } const size_t read = pStream->Read(buffer,1,searchBytes); if( !read ) { From cfcaf3e97b382d4e30f2cdc2fd96af3bde632a9f Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 17:38:30 +0200 Subject: [PATCH 10/11] BVH: Initialize all members of Node in constructor --- code/BVHLoader.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/BVHLoader.h b/code/BVHLoader.h index 0836488ff..a18ad81d9 100644 --- a/code/BVHLoader.h +++ b/code/BVHLoader.h @@ -84,7 +84,10 @@ class BVHLoader : public BaseImporter std::vector mChannels; std::vector mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames - Node() { } + Node() + : mNode(nullptr) + { } + explicit Node( const aiNode* pNode) : mNode( pNode) { } }; From 5278e1a5f85dc51f5e0f4c2be28e5b4fffce0227 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 3 Feb 2018 17:52:25 +0200 Subject: [PATCH 11/11] CSM: Fix a possible memory leak by using std::unique_ptr --- code/CSMLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/CSMLoader.cpp b/code/CSMLoader.cpp index 7b0064164..7160740c1 100644 --- a/code/CSMLoader.cpp +++ b/code/CSMLoader.cpp @@ -136,7 +136,7 @@ void CSMImporter::InternReadFile( const std::string& pFile, TextFileToBuffer(file.get(),mBuffer2); const char* buffer = &mBuffer2[0]; - aiAnimation* anim = new aiAnimation(); + std::unique_ptr anim(new aiAnimation()); int first = 0, last = 0x00ffffff; // now process the file and look out for '$' sections @@ -294,8 +294,8 @@ void CSMImporter::InternReadFile( const std::string& pFile, // Store the one and only animation in the scene pScene->mAnimations = new aiAnimation*[pScene->mNumAnimations=1]; - pScene->mAnimations[0] = anim; anim->mName.Set("$CSM_MasterAnim"); + pScene->mAnimations[0] = anim.release(); // mark the scene as incomplete and run SkeletonMeshBuilder on it pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;