fix memory leak
parent
bd032488e4
commit
4af9632269
|
@ -53,7 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "../include/assimp/DefaultLogger.hpp"
|
||||
#include "Macros.h"
|
||||
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -571,9 +570,11 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
|||
for (unsigned int i = 0; i < iOldNum;++i) {
|
||||
pcDest->mProperties[i] = pcOld[i];
|
||||
}
|
||||
|
||||
delete[] pcOld;
|
||||
}
|
||||
|
||||
if(pcOld)
|
||||
delete[] pcOld;
|
||||
|
||||
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
|
||||
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
||||
|
||||
|
@ -605,4 +606,3 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,8 @@ public:
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
/** Closes the given file and releases all resources associated with it. */
|
||||
void Close( IOStream* /*pFile*/) {
|
||||
void Close( IOStream* pFile) {
|
||||
delete pFile;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
@ -283,7 +283,7 @@ bool RemoveVCProcess::ProcessMesh(aiMesh* pMesh)
|
|||
if (!pMesh->mTextureCoords[i])break;
|
||||
if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b)
|
||||
{
|
||||
delete pMesh->mTextureCoords[i];
|
||||
delete [] pMesh->mTextureCoords[i];
|
||||
pMesh->mTextureCoords[i] = NULL;
|
||||
ret = true;
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ protected:
|
|||
RemoveRedundantMatsProcess* piProcess;
|
||||
|
||||
aiScene* pcScene1;
|
||||
aiScene* pcScene2;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -59,28 +59,16 @@ protected:
|
|||
SharedPostProcessInfo* shared;
|
||||
};
|
||||
|
||||
static bool destructed;
|
||||
|
||||
struct TestType
|
||||
{
|
||||
~TestType()
|
||||
{
|
||||
destructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SharedPPDataTest::SetUp()
|
||||
{
|
||||
shared = new SharedPostProcessInfo();
|
||||
destructed = false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SharedPPDataTest::TearDown()
|
||||
{
|
||||
|
||||
delete shared;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -112,14 +100,26 @@ TEST_F(SharedPPDataTest, testPropertyPointer)
|
|||
EXPECT_FALSE(shared->GetProperty("test16",o));
|
||||
}
|
||||
|
||||
static bool destructed;
|
||||
|
||||
struct TestType
|
||||
{
|
||||
~TestType()
|
||||
{
|
||||
destructed = true;
|
||||
}
|
||||
};
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
TEST_F(SharedPPDataTest, testPropertyDeallocation)
|
||||
{
|
||||
TestType *out, * pip = new TestType();
|
||||
shared->AddProperty("quak",pip);
|
||||
EXPECT_TRUE(shared->GetProperty("quak",out));
|
||||
SharedPostProcessInfo* localShared = new SharedPostProcessInfo();
|
||||
destructed = false;
|
||||
|
||||
TestType *out, * pip = new TestType();
|
||||
localShared->AddProperty("quak",pip);
|
||||
EXPECT_TRUE(localShared->GetProperty("quak",out));
|
||||
EXPECT_EQ(pip, out);
|
||||
|
||||
delete shared;
|
||||
delete localShared;
|
||||
EXPECT_TRUE(destructed);
|
||||
}
|
||||
|
|
|
@ -58,8 +58,7 @@ protected:
|
|||
|
||||
SplitLargeMeshesProcess_Triangle* piProcessTriangle;
|
||||
SplitLargeMeshesProcess_Vertex* piProcessVertex;
|
||||
aiMesh* pcMesh1;
|
||||
aiMesh* pcMesh2;
|
||||
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -72,44 +71,6 @@ void SplitLargeMeshesTest::SetUp()
|
|||
this->piProcessTriangle->SetLimit(1000);
|
||||
this->piProcessVertex->SetLimit(1000);
|
||||
|
||||
this->pcMesh1 = new aiMesh();
|
||||
pcMesh1->mNumVertices = 2100; // quersumme: 3
|
||||
pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
|
||||
pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
|
||||
|
||||
pcMesh1->mNumFaces = pcMesh1->mNumVertices / 3;
|
||||
pcMesh1->mFaces = new aiFace[pcMesh1->mNumFaces];
|
||||
|
||||
unsigned int qq = 0;
|
||||
for (unsigned int i = 0; i < pcMesh1->mNumFaces;++i)
|
||||
{
|
||||
aiFace& face = pcMesh1->mFaces[i];
|
||||
face.mNumIndices = 3;
|
||||
face.mIndices = new unsigned int[3];
|
||||
face.mIndices[0] = qq++;
|
||||
face.mIndices[1] = qq++;
|
||||
face.mIndices[2] = qq++;
|
||||
}
|
||||
|
||||
// generate many, many faces with randomized indices for
|
||||
// the second mesh
|
||||
this->pcMesh2 = new aiMesh();
|
||||
pcMesh2->mNumVertices = 3000;
|
||||
pcMesh2->mVertices = new aiVector3D[pcMesh2->mNumVertices];
|
||||
pcMesh2->mNormals = new aiVector3D[pcMesh2->mNumVertices];
|
||||
|
||||
pcMesh2->mNumFaces = 10000;
|
||||
pcMesh2->mFaces = new aiFace[pcMesh2->mNumFaces];
|
||||
|
||||
for (unsigned int i = 0; i < pcMesh2->mNumFaces;++i)
|
||||
{
|
||||
aiFace& face = pcMesh2->mFaces[i];
|
||||
face.mNumIndices = 3;
|
||||
face.mIndices = new unsigned int[3];
|
||||
face.mIndices[0] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
face.mIndices[1] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
face.mIndices[2] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -124,6 +85,26 @@ TEST_F(SplitLargeMeshesTest, testVertexSplit)
|
|||
{
|
||||
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
|
||||
|
||||
aiMesh *pcMesh1 = new aiMesh();
|
||||
pcMesh1->mNumVertices = 2100; // quersumme: 3
|
||||
pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
|
||||
pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
|
||||
|
||||
pcMesh1->mNumFaces = pcMesh1->mNumVertices / 3;
|
||||
pcMesh1->mFaces = new aiFace[pcMesh1->mNumFaces];
|
||||
|
||||
unsigned int qq = 0;
|
||||
for (unsigned int i = 0; i < pcMesh1->mNumFaces;++i)
|
||||
{
|
||||
aiFace& face = pcMesh1->mFaces[i];
|
||||
face.mNumIndices = 3;
|
||||
face.mIndices = new unsigned int[3];
|
||||
face.mIndices[0] = qq++;
|
||||
face.mIndices[1] = qq++;
|
||||
face.mIndices[2] = qq++;
|
||||
}
|
||||
|
||||
|
||||
int iOldFaceNum = (int)pcMesh1->mNumFaces;
|
||||
piProcessVertex->SplitMesh(0,pcMesh1,avOut);
|
||||
|
||||
|
@ -147,6 +128,26 @@ TEST_F(SplitLargeMeshesTest, testTriangleSplit)
|
|||
{
|
||||
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
|
||||
|
||||
// generate many, many faces with randomized indices for
|
||||
// the second mesh
|
||||
aiMesh *pcMesh2 = new aiMesh();
|
||||
pcMesh2->mNumVertices = 3000;
|
||||
pcMesh2->mVertices = new aiVector3D[pcMesh2->mNumVertices];
|
||||
pcMesh2->mNormals = new aiVector3D[pcMesh2->mNumVertices];
|
||||
|
||||
pcMesh2->mNumFaces = 10000;
|
||||
pcMesh2->mFaces = new aiFace[pcMesh2->mNumFaces];
|
||||
|
||||
for (unsigned int i = 0; i < pcMesh2->mNumFaces;++i)
|
||||
{
|
||||
aiFace& face = pcMesh2->mFaces[i];
|
||||
face.mNumIndices = 3;
|
||||
face.mIndices = new unsigned int[3];
|
||||
face.mIndices[0] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
face.mIndices[1] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
face.mIndices[2] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
|
||||
}
|
||||
|
||||
// the number of faces shouldn't change
|
||||
int iOldFaceNum = (int)pcMesh2->mNumFaces;
|
||||
piProcessTriangle->SplitMesh(0,pcMesh2,avOut);
|
||||
|
|
Loading…
Reference in New Issue