Merge pull request #753 from wise86-android/ValgrinFree

Valgrin free
pull/756/head
Kim Kulling 2016-01-19 16:34:58 +01:00
commit 9e6f22b913
15 changed files with 107 additions and 85 deletions

View File

@ -485,9 +485,9 @@ struct aiFloatKey
/** Helper structure to represent a 3ds file node */ /** Helper structure to represent a 3ds file node */
struct Node struct Node
{ {
Node() Node():
: mParent() mParent(NULL)
, mInstanceNumber() , mInstanceNumber(0)
, mHierarchyPos (0) , mHierarchyPos (0)
, mHierarchyIndex (0) , mHierarchyIndex (0)
, mInstanceCount (1) , mInstanceCount (1)

View File

@ -96,6 +96,8 @@ namespace Assimp
/** will return all registered importers. */ /** will return all registered importers. */
void GetImporterInstanceList(std::vector< BaseImporter* >& out); void GetImporterInstanceList(std::vector< BaseImporter* >& out);
/** will delete all registered importers. */
void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
} // namespace assimp } // namespace assimp
@ -648,6 +650,8 @@ ASSIMP_API C_STRUCT const aiImporterDesc* aiGetImporterDesc( const char *extensi
} }
} }
DeleteImporterInstanceList(out);
return desc; return desc;
} }

View File

@ -90,6 +90,8 @@ using namespace Assimp::Formatter;
namespace Assimp { namespace Assimp {
// ImporterRegistry.cpp // ImporterRegistry.cpp
void GetImporterInstanceList(std::vector< BaseImporter* >& out); void GetImporterInstanceList(std::vector< BaseImporter* >& out);
void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
// PostStepRegistry.cpp // PostStepRegistry.cpp
void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out); void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
} }
@ -173,8 +175,7 @@ Importer::Importer()
Importer::~Importer() Importer::~Importer()
{ {
// Delete all import plugins // Delete all import plugins
for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) DeleteImporterInstanceList(pimpl->mImporter);
delete pimpl->mImporter[a];
// Delete all post-processing plug-ins // Delete all post-processing plug-ins
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++)
@ -1113,4 +1114,3 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
} }
in.total += in.materials; in.total += in.materials;
} }

View File

@ -321,4 +321,12 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out)
#endif #endif
} }
/** will delete all registered importers. */
void DeleteImporterInstanceList(std::vector< BaseImporter* >& deleteList){
for(size_t i= 0; i<deleteList.size();++i){
delete deleteList[i];
deleteList[i]=NULL;
}//for
}
} // namespace Assimp } // namespace Assimp

View File

@ -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;
} }

View File

@ -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;
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -183,7 +183,9 @@ OpenGEXImporter::VertexContainer::VertexContainer()
, m_numNormals( 0 ) , m_numNormals( 0 )
, m_normals(NULL) , m_normals(NULL)
, m_numUVComps() , m_numUVComps()
, m_textureCoords() { , m_textureCoords()
{
// empty
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -217,6 +219,7 @@ OpenGEXImporter::OpenGEXImporter()
, m_ctx( NULL ) , m_ctx( NULL )
, m_metrics() , m_metrics()
, m_currentNode( NULL ) , m_currentNode( NULL )
, m_currentVertices()
, m_currentMesh( NULL ) , m_currentMesh( NULL )
, m_currentMaterial( NULL ) , m_currentMaterial( NULL )
, m_tokenType( Grammar::NoneType ) , m_tokenType( Grammar::NoneType )
@ -661,6 +664,7 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene
} }
const size_t numItems( countDataArrayListItems( vaList ) ); const size_t numItems( countDataArrayListItems( vaList ) );
if( Position == attribType ) { if( Position == attribType ) {
m_currentVertices.m_numVerts = numItems; m_currentVertices.m_numVerts = numItems;
m_currentVertices.m_vertices = new aiVector3D[ numItems ]; m_currentVertices.m_vertices = new aiVector3D[ numItems ];

View File

@ -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;

View File

@ -73,10 +73,12 @@ SkeletonMeshBuilder::SkeletonMeshBuilder( aiScene* pScene, aiNode* root, bool bK
root->mMeshes[0] = 0; root->mMeshes[0] = 0;
// create a dummy material for the mesh // create a dummy material for the mesh
if(pScene->mNumMaterials==0){
pScene->mNumMaterials = 1; pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial*[1]; pScene->mMaterials = new aiMaterial*[1];
pScene->mMaterials[0] = CreateMaterial(); pScene->mMaterials[0] = CreateMaterial();
} }
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Recursively builds a simple mesh representation for the given node // Recursively builds a simple mesh representation for the given node

View File

@ -137,8 +137,10 @@ namespace {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor for a specific scene to export // Constructor for a specific scene to export
StepExporter::StepExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties) : mProperties(pProperties), mIOSystem(pIOSystem), mFile(file), mPath(path), mScene(pScene), endstr(";\n") StepExporter::StepExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path,
{ const std::string& file, const ExportProperties* pProperties):
mProperties(pProperties),mIOSystem(pIOSystem),mFile(file), mPath(path),
mScene(pScene), endstr(";\n") {
CollectTrafos(pScene->mRootNode, trafos); CollectTrafos(pScene->mRootNode, trafos);
CollectMeshes(pScene->mRootNode, meshes); CollectMeshes(pScene->mRootNode, meshes);

View File

@ -54,7 +54,6 @@ public:
{ {
ex = new Assimp::Exporter(); ex = new Assimp::Exporter();
im = new Assimp::Importer(); im = new Assimp::Importer();
} }
virtual void TearDown() virtual void TearDown()
@ -73,7 +72,7 @@ protected:
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
TEST_F(ColladaExportLight, testExportLight) TEST_F(ColladaExportLight, testExportLight)
{ {
const char* file = "cameraExp.dae"; const char* file = "lightsExp.dae";
const aiScene* pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/lights.dae",0); const aiScene* pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/lights.dae",0);
ASSERT_TRUE(pTest!=NULL); ASSERT_TRUE(pTest!=NULL);
@ -88,7 +87,6 @@ TEST_F(ColladaExportLight, testExportLight)
} }
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file)); EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada","lightsExp.dae"));
const aiScene* imported = im->ReadFile(file,0); const aiScene* imported = im->ReadFile(file,0);
@ -123,7 +121,9 @@ TEST_F(ColladaExportLight, testExportLight)
EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001); EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001);
EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001); EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001);
} }
delete [] origLights; delete [] origLights;
} }

View File

@ -76,7 +76,8 @@ TEST(NoBoostTest, Tuple) {
EXPECT_EQ(4U, first.get<1>()); EXPECT_EQ(4U, first.get<1>());
EXPECT_EQ(4U, first.get<2>()); EXPECT_EQ(4U, first.get<2>());
boost::tuple<int, float, double, bool, another> second; boost::tuple<int, float, double, bool, another> second=
boost::make_tuple(1,1.0f,0.0,false,another());
bool b = second.get<3>(); bool b = second.get<3>();
// check empty tuple // check empty tuple

View File

@ -60,7 +60,6 @@ protected:
RemoveRedundantMatsProcess* piProcess; RemoveRedundantMatsProcess* piProcess;
aiScene* pcScene1; aiScene* pcScene1;
aiScene* pcScene2;
}; };
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -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);
} }

View File

@ -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);