Skip to content

Commit

Permalink
closes code/SortByPTypeProcess.cpp: fix memory leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling committed May 2, 2018
1 parent 6ef9e88 commit a0bf664
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions code/SortByPTypeProcess.cpp
Expand Up @@ -85,8 +85,6 @@ void SortByPTypeProcess::SetupProperties(const Importer* pImp)
// Update changed meshes in all nodes
void UpdateNodes(const std::vector<unsigned int>& replaceMeshIndex, aiNode* node)
{
// std::vector<unsigned int>::const_iterator it;

if (node->mNumMeshes)
{
unsigned int newSize = 0;
Expand Down Expand Up @@ -133,10 +131,8 @@ void UpdateNodes(const std::vector<unsigned int>& replaceMeshIndex, aiNode* node

// ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data.
void SortByPTypeProcess::Execute( aiScene* pScene)
{
if (!pScene->mNumMeshes)
{
void SortByPTypeProcess::Execute( aiScene* pScene) {
if ( 0 == pScene->mNumMeshes) {
ASSIMP_LOG_DEBUG("SortByPTypeProcess skipped, there are no meshes");
return;
}
Expand All @@ -152,57 +148,52 @@ void SortByPTypeProcess::Execute( aiScene* pScene)

std::vector<unsigned int> replaceMeshIndex(pScene->mNumMeshes*4,UINT_MAX);
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];
ai_assert(0 != mesh->mPrimitiveTypes);

// if there's just one primitive type in the mesh there's nothing to do for us
unsigned int num = 0;
if (mesh->mPrimitiveTypes & aiPrimitiveType_POINT)
{
if (mesh->mPrimitiveTypes & aiPrimitiveType_POINT) {
++aiNumMeshesPerPType[0];
++num;
}
if (mesh->mPrimitiveTypes & aiPrimitiveType_LINE)
{
if (mesh->mPrimitiveTypes & aiPrimitiveType_LINE) {
++aiNumMeshesPerPType[1];
++num;
}
if (mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE)
{
if (mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) {
++aiNumMeshesPerPType[2];
++num;
}
if (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)
{
if (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON) {
++aiNumMeshesPerPType[3];
++num;
}

if (1 == num)
{
if (!(configRemoveMeshes & mesh->mPrimitiveTypes))
{
*meshIdx = (unsigned int) outMeshes.size();
if (1 == num) {
if (!(configRemoveMeshes & mesh->mPrimitiveTypes)) {
*meshIdx = static_cast<unsigned int>( outMeshes.size() );
outMeshes.push_back(mesh);
} else {
delete mesh;
pScene->mMeshes[ i ] = nullptr;
bAnyChanges = true;
}
else bAnyChanges = true;

meshIdx += 4;
continue;
}
bAnyChanges = true;

// 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};
aiFace* pFirstFace = mesh->mFaces;
aiFace* const pLastFace = pFirstFace + mesh->mNumFaces;

unsigned int numPolyVerts = 0;
for (;pFirstFace != pLastFace; ++pFirstFace)
{
for (;pFirstFace != pLastFace; ++pFirstFace) {
if (pFirstFace->mNumIndices <= 3)
++aiNumPerPType[pFirstFace->mNumIndices-1];
else
Expand Down

0 comments on commit a0bf664

Please sign in to comment.