From dfbae1294fa568145ccb7ebafa4f88b99e039ed9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 5 Feb 2016 18:53:23 +0100 Subject: [PATCH] JoinVerticesProcess: iAdd test for possible null pointer access. --- code/JoinVerticesProcess.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/code/JoinVerticesProcess.cpp b/code/JoinVerticesProcess.cpp index 4952a27b3..7874d97e7 100644 --- a/code/JoinVerticesProcess.cpp +++ b/code/JoinVerticesProcess.cpp @@ -357,23 +357,24 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) } // adjust bone vertex weights. - for( int a = 0; a < (int)pMesh->mNumBones; a++) - { + for( int a = 0; a < (int)pMesh->mNumBones; a++) { aiBone* bone = pMesh->mBones[a]; std::vector newWeights; newWeights.reserve( bone->mNumWeights); - for( unsigned int b = 0; b < bone->mNumWeights; b++) - { - const aiVertexWeight& ow = bone->mWeights[b]; - // if the vertex is a unique one, translate it - if( !(replaceIndex[ow.mVertexId] & 0x80000000)) - { - aiVertexWeight nw; - nw.mVertexId = replaceIndex[ow.mVertexId]; - nw.mWeight = ow.mWeight; - newWeights.push_back( nw); + if ( NULL != bone->mWeights ) { + for ( unsigned int b = 0; b < bone->mNumWeights; b++ ) { + const aiVertexWeight& ow = bone->mWeights[ b ]; + // if the vertex is a unique one, translate it + if ( !( replaceIndex[ ow.mVertexId ] & 0x80000000 ) ) { + aiVertexWeight nw; + nw.mVertexId = replaceIndex[ ow.mVertexId ]; + nw.mWeight = ow.mWeight; + newWeights.push_back( nw ); + } } + } else { + DefaultLogger::get()->error( "X-Export: aiBone shall contain weights, but pointer to them is NULL." ); } if (newWeights.size() > 0) {