From 68ef00ef09deca327045fe7bf81e6ca43bab0ff7 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Sun, 16 Nov 2008 14:39:54 +0000 Subject: [PATCH] Fixed a bug in the SortByPType-step causing some models with bones to crash Fixed a bug in PretransformVertices - vertex colors caused an infinite loop sometimes. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@241 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/PretransformVertices.cpp | 2 +- code/SortByPTypeProcess.cpp | 4 ++-- include/aiAnim.h | 5 ++++- include/aiMesh.h | 11 ++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 530037bc8..72e731502 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -360,7 +360,7 @@ void PretransformVertices::Execute( aiScene* pScene) } iFaces = 0; while ((*j) & (0x1000000 << iFaces)) - pcMesh->mColors[iFaces] = new aiColor4D[iVertices]; + pcMesh->mColors[iFaces++] = new aiColor4D[iVertices]; // fill the mesh ... unsigned int aiTemp[2] = {0,0}; diff --git a/code/SortByPTypeProcess.cpp b/code/SortByPTypeProcess.cpp index 14358e307..155370028 100644 --- a/code/SortByPTypeProcess.cpp +++ b/code/SortByPTypeProcess.cpp @@ -298,7 +298,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene) for (VertexWeightTable::const_iterator it = tbl.begin(), end = tbl.end(); it != end; ++it) { - tempBones[ (*it).first ].push_back( aiVertexWeight(idx, (*it).second) ); + tempBones[ (*it).first ].push_back( aiVertexWeight(outIdx, (*it).second) ); } } @@ -355,7 +355,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene) bone->mNumWeights = (unsigned int)in.size(); bone->mWeights = new aiVertexWeight[bone->mNumWeights]; - ::memcpy(bone->mWeights,&in[0],bone->mNumWeights*sizeof(void*)); + ::memcpy(bone->mWeights,&in[0],bone->mNumWeights*sizeof(aiVertexWeight)); ++real; } diff --git a/include/aiAnim.h b/include/aiAnim.h index 6125c0fb9..21d3d07ba 100644 --- a/include/aiAnim.h +++ b/include/aiAnim.h @@ -274,11 +274,14 @@ struct aiAnimation ~aiAnimation() { - if (mNumChannels) + // DO NOT REMOVE THIS ADDITIONAL CHECK + if (mNumChannels && mChannels) + { for( unsigned int a = 0; a < mNumChannels; a++) delete mChannels[a]; delete [] mChannels; + } } #endif // __cplusplus }; diff --git a/include/aiMesh.h b/include/aiMesh.h index fe3bab07f..8ef7e5742 100644 --- a/include/aiMesh.h +++ b/include/aiMesh.h @@ -452,9 +452,14 @@ struct aiMesh delete [] mTextureCoords[a]; for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) delete [] mColors[a]; - for( unsigned int a = 0; a < mNumBones; a++) - delete mBones[a]; - delete [] mBones; + + // DO NOT REMOVE THIS ADDITIONAL CHECK + if (mNumBones && mBones) + { + for( unsigned int a = 0; a < mNumBones; a++) + delete mBones[a]; + delete [] mBones; + } delete [] mFaces; }