closes code/SortByPTypeProcess.cpp: fix memory leak.

pull/1939/head
kimkulling 2018-05-02 16:42:22 +02:00
parent 6ef9e8848d
commit a0bf664695
1 changed files with 16 additions and 25 deletions

View File

@ -85,8 +85,6 @@ void SortByPTypeProcess::SetupProperties(const Importer* pImp)
// Update changed meshes in all nodes // Update changed meshes in all nodes
void UpdateNodes(const std::vector<unsigned int>& replaceMeshIndex, aiNode* node) void UpdateNodes(const std::vector<unsigned int>& replaceMeshIndex, aiNode* node)
{ {
// std::vector<unsigned int>::const_iterator it;
if (node->mNumMeshes) if (node->mNumMeshes)
{ {
unsigned int newSize = 0; unsigned int newSize = 0;
@ -133,10 +131,8 @@ void UpdateNodes(const std::vector<unsigned int>& replaceMeshIndex, aiNode* node
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data. // Executes the post processing step on the given imported data.
void SortByPTypeProcess::Execute( aiScene* pScene) void SortByPTypeProcess::Execute( aiScene* pScene) {
{ if ( 0 == pScene->mNumMeshes) {
if (!pScene->mNumMeshes)
{
ASSIMP_LOG_DEBUG("SortByPTypeProcess skipped, there are no meshes"); ASSIMP_LOG_DEBUG("SortByPTypeProcess skipped, there are no meshes");
return; return;
} }
@ -152,42 +148,38 @@ void SortByPTypeProcess::Execute( aiScene* pScene)
std::vector<unsigned int> replaceMeshIndex(pScene->mNumMeshes*4,UINT_MAX); std::vector<unsigned int> replaceMeshIndex(pScene->mNumMeshes*4,UINT_MAX);
std::vector<unsigned int>::iterator meshIdx = replaceMeshIndex.begin(); std::vector<unsigned int>::iterator meshIdx = replaceMeshIndex.begin();
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
{
aiMesh* const mesh = pScene->mMeshes[i]; aiMesh* const mesh = pScene->mMeshes[i];
ai_assert(0 != mesh->mPrimitiveTypes); ai_assert(0 != mesh->mPrimitiveTypes);
// if there's just one primitive type in the mesh there's nothing to do for us // if there's just one primitive type in the mesh there's nothing to do for us
unsigned int num = 0; unsigned int num = 0;
if (mesh->mPrimitiveTypes & aiPrimitiveType_POINT) if (mesh->mPrimitiveTypes & aiPrimitiveType_POINT) {
{
++aiNumMeshesPerPType[0]; ++aiNumMeshesPerPType[0];
++num; ++num;
} }
if (mesh->mPrimitiveTypes & aiPrimitiveType_LINE) if (mesh->mPrimitiveTypes & aiPrimitiveType_LINE) {
{
++aiNumMeshesPerPType[1]; ++aiNumMeshesPerPType[1];
++num; ++num;
} }
if (mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) if (mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) {
{
++aiNumMeshesPerPType[2]; ++aiNumMeshesPerPType[2];
++num; ++num;
} }
if (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON) if (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON) {
{
++aiNumMeshesPerPType[3]; ++aiNumMeshesPerPType[3];
++num; ++num;
} }
if (1 == num) if (1 == num) {
{ if (!(configRemoveMeshes & mesh->mPrimitiveTypes)) {
if (!(configRemoveMeshes & mesh->mPrimitiveTypes)) *meshIdx = static_cast<unsigned int>( outMeshes.size() );
{
*meshIdx = (unsigned int) outMeshes.size();
outMeshes.push_back(mesh); outMeshes.push_back(mesh);
} else {
delete mesh;
pScene->mMeshes[ i ] = nullptr;
bAnyChanges = true;
} }
else bAnyChanges = true;
meshIdx += 4; meshIdx += 4;
continue; continue;
@ -195,14 +187,13 @@ void SortByPTypeProcess::Execute( aiScene* pScene)
bAnyChanges = true; bAnyChanges = true;
// reuse our current mesh arrays for the submesh // reuse our current mesh arrays for the submesh
// with the largest numer of primitives // with the largest number of primitives
unsigned int aiNumPerPType[4] = {0,0,0,0}; unsigned int aiNumPerPType[4] = {0,0,0,0};
aiFace* pFirstFace = mesh->mFaces; aiFace* pFirstFace = mesh->mFaces;
aiFace* const pLastFace = pFirstFace + mesh->mNumFaces; aiFace* const pLastFace = pFirstFace + mesh->mNumFaces;
unsigned int numPolyVerts = 0; unsigned int numPolyVerts = 0;
for (;pFirstFace != pLastFace; ++pFirstFace) for (;pFirstFace != pLastFace; ++pFirstFace) {
{
if (pFirstFace->mNumIndices <= 3) if (pFirstFace->mNumIndices <= 3)
++aiNumPerPType[pFirstFace->mNumIndices-1]; ++aiNumPerPType[pFirstFace->mNumIndices-1];
else else