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 "../include/assimp/DefaultLogger.hpp"
|
||||||
#include "Macros.h"
|
#include "Macros.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -571,9 +570,11 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
||||||
for (unsigned int i = 0; i < iOldNum;++i) {
|
for (unsigned int i = 0; i < iOldNum;++i) {
|
||||||
pcDest->mProperties[i] = pcOld[i];
|
pcDest->mProperties[i] = pcOld[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] pcOld;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pcOld)
|
||||||
|
delete[] pcOld;
|
||||||
|
|
||||||
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
|
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
|
||||||
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
||||||
|
|
||||||
|
@ -605,4 +606,3 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,8 @@ public:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Closes the given file and releases all resources associated with it. */
|
/** 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 (!pMesh->mTextureCoords[i])break;
|
||||||
if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b)
|
if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b)
|
||||||
{
|
{
|
||||||
delete pMesh->mTextureCoords[i];
|
delete [] pMesh->mTextureCoords[i];
|
||||||
pMesh->mTextureCoords[i] = NULL;
|
pMesh->mTextureCoords[i] = NULL;
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ protected:
|
||||||
RemoveRedundantMatsProcess* piProcess;
|
RemoveRedundantMatsProcess* piProcess;
|
||||||
|
|
||||||
aiScene* pcScene1;
|
aiScene* pcScene1;
|
||||||
aiScene* pcScene2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -59,28 +59,16 @@ protected:
|
||||||
SharedPostProcessInfo* shared;
|
SharedPostProcessInfo* shared;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool destructed;
|
|
||||||
|
|
||||||
struct TestType
|
|
||||||
{
|
|
||||||
~TestType()
|
|
||||||
{
|
|
||||||
destructed = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void SharedPPDataTest::SetUp()
|
void SharedPPDataTest::SetUp()
|
||||||
{
|
{
|
||||||
shared = new SharedPostProcessInfo();
|
shared = new SharedPostProcessInfo();
|
||||||
destructed = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void SharedPPDataTest::TearDown()
|
void SharedPPDataTest::TearDown()
|
||||||
{
|
{
|
||||||
|
delete shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -112,14 +100,26 @@ TEST_F(SharedPPDataTest, testPropertyPointer)
|
||||||
EXPECT_FALSE(shared->GetProperty("test16",o));
|
EXPECT_FALSE(shared->GetProperty("test16",o));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool destructed;
|
||||||
|
|
||||||
|
struct TestType
|
||||||
|
{
|
||||||
|
~TestType()
|
||||||
|
{
|
||||||
|
destructed = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
TEST_F(SharedPPDataTest, testPropertyDeallocation)
|
TEST_F(SharedPPDataTest, testPropertyDeallocation)
|
||||||
{
|
{
|
||||||
|
SharedPostProcessInfo* localShared = new SharedPostProcessInfo();
|
||||||
|
destructed = false;
|
||||||
|
|
||||||
TestType *out, * pip = new TestType();
|
TestType *out, * pip = new TestType();
|
||||||
shared->AddProperty("quak",pip);
|
localShared->AddProperty("quak",pip);
|
||||||
EXPECT_TRUE(shared->GetProperty("quak",out));
|
EXPECT_TRUE(localShared->GetProperty("quak",out));
|
||||||
EXPECT_EQ(pip, out);
|
EXPECT_EQ(pip, out);
|
||||||
|
|
||||||
delete shared;
|
delete localShared;
|
||||||
EXPECT_TRUE(destructed);
|
EXPECT_TRUE(destructed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,7 @@ protected:
|
||||||
|
|
||||||
SplitLargeMeshesProcess_Triangle* piProcessTriangle;
|
SplitLargeMeshesProcess_Triangle* piProcessTriangle;
|
||||||
SplitLargeMeshesProcess_Vertex* piProcessVertex;
|
SplitLargeMeshesProcess_Vertex* piProcessVertex;
|
||||||
aiMesh* pcMesh1;
|
|
||||||
aiMesh* pcMesh2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -72,7 +71,21 @@ void SplitLargeMeshesTest::SetUp()
|
||||||
this->piProcessTriangle->SetLimit(1000);
|
this->piProcessTriangle->SetLimit(1000);
|
||||||
this->piProcessVertex->SetLimit(1000);
|
this->piProcessVertex->SetLimit(1000);
|
||||||
|
|
||||||
this->pcMesh1 = new aiMesh();
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void SplitLargeMeshesTest::TearDown()
|
||||||
|
{
|
||||||
|
delete this->piProcessTriangle;
|
||||||
|
delete this->piProcessVertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
TEST_F(SplitLargeMeshesTest, testVertexSplit)
|
||||||
|
{
|
||||||
|
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
|
||||||
|
|
||||||
|
aiMesh *pcMesh1 = new aiMesh();
|
||||||
pcMesh1->mNumVertices = 2100; // quersumme: 3
|
pcMesh1->mNumVertices = 2100; // quersumme: 3
|
||||||
pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
|
pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
|
||||||
pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
|
pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
|
||||||
|
@ -91,38 +104,6 @@ void SplitLargeMeshesTest::SetUp()
|
||||||
face.mIndices[2] = 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void SplitLargeMeshesTest::TearDown()
|
|
||||||
{
|
|
||||||
delete this->piProcessTriangle;
|
|
||||||
delete this->piProcessVertex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
TEST_F(SplitLargeMeshesTest, testVertexSplit)
|
|
||||||
{
|
|
||||||
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
|
|
||||||
|
|
||||||
int iOldFaceNum = (int)pcMesh1->mNumFaces;
|
int iOldFaceNum = (int)pcMesh1->mNumFaces;
|
||||||
piProcessVertex->SplitMesh(0,pcMesh1,avOut);
|
piProcessVertex->SplitMesh(0,pcMesh1,avOut);
|
||||||
|
@ -147,6 +128,26 @@ TEST_F(SplitLargeMeshesTest, testTriangleSplit)
|
||||||
{
|
{
|
||||||
std::vector< std::pair<aiMesh*, unsigned int> > avOut;
|
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
|
// the number of faces shouldn't change
|
||||||
int iOldFaceNum = (int)pcMesh2->mNumFaces;
|
int iOldFaceNum = (int)pcMesh2->mNumFaces;
|
||||||
piProcessTriangle->SplitMesh(0,pcMesh2,avOut);
|
piProcessTriangle->SplitMesh(0,pcMesh2,avOut);
|
||||||
|
|
Loading…
Reference in New Issue