Fix resource leak.

pull/933/head
Kim Kulling 2016-07-04 20:19:24 +02:00
parent 19ba6448f0
commit 32e8c80c24
2 changed files with 35 additions and 21 deletions

View File

@ -12,5 +12,26 @@
#include <math.h> #include <math.h>
template<class T>
struct TDataArray {
size_t m_numItems;
T *m_items;
TDataArray( size_t numItems )
: m_numItems( numItems )
, m_items( nullptr ) {
m_items = new T[ numItems ];
}
~TDataArray() {
delete [] m_items;
}
T operator [] ( size_t index ) const {
EXPECT_TRUE( index < m_numItems );
return m_items[ index ];
}
};
#undef min #undef min
#undef max #undef max

View File

@ -64,13 +64,10 @@ public:
} }
protected: protected:
Assimp::Exporter* ex; Assimp::Exporter* ex;
Assimp::Importer* im; Assimp::Importer* im;
}; };
// ------------------------------------------------------------------------------------------------
TEST_F(ColladaExportCamera, testExportCamera) TEST_F(ColladaExportCamera, testExportCamera)
{ {
const char* file = "cameraExp.dae"; const char* file = "cameraExp.dae";
@ -82,18 +79,21 @@ TEST_F(ColladaExportCamera, testExportCamera)
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file)); EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
const unsigned int origNumCams( pTest->mNumCameras ); const unsigned int origNumCams( pTest->mNumCameras );
float *origFOV = new float[ origNumCams ]; //float *origFOV = new float[ origNumCams ];
float *orifClipPlaneNear = new float[ origNumCams ]; TDataArray<float> origFOV( origNumCams );
float *orifClipPlaneFar = new float[ origNumCams ]; TDataArray<float> orifClipPlaneNear( origNumCams );
aiString *names = new aiString[ origNumCams ]; TDataArray<float> orifClipPlaneFar( origNumCams );
aiVector3D *pos = new aiVector3D[ origNumCams ]; TDataArray<aiString> names( origNumCams );
TDataArray<aiVector3D> pos( origNumCams );
for (size_t i = 0; i < origNumCams; i++) { for (size_t i = 0; i < origNumCams; i++) {
const aiCamera *orig = pTest->mCameras[ i ]; const aiCamera *orig = pTest->mCameras[ i ];
origFOV[ i ] = orig->mHorizontalFOV; ASSERT_TRUE( orig != nullptr );
orifClipPlaneNear[ i ] = orig->mClipPlaneNear;
orifClipPlaneFar[ i ] = orig->mClipPlaneFar; origFOV.m_items[ i ] = orig->mHorizontalFOV;
names[ i ] = orig->mName; orifClipPlaneNear.m_items[ i ] = orig->mClipPlaneNear;
pos[ i ] = orig->mPosition; orifClipPlaneFar.m_items[ i ] = orig->mClipPlaneFar;
names.m_items[ i ] = orig->mName;
pos.m_items[ i ] = orig->mPosition;
} }
const aiScene* imported = im->ReadFile(file,0); const aiScene* imported = im->ReadFile(file,0);
@ -114,15 +114,8 @@ TEST_F(ColladaExportCamera, testExportCamera)
EXPECT_FLOAT_EQ( pos[ i ].y,read->mPosition.y); EXPECT_FLOAT_EQ( pos[ i ].y,read->mPosition.y);
EXPECT_FLOAT_EQ( pos[ i ].z,read->mPosition.z); EXPECT_FLOAT_EQ( pos[ i ].z,read->mPosition.z);
} }
delete [] origFOV;
delete [] orifClipPlaneNear;
delete [] orifClipPlaneFar;
delete [] names;
delete [] pos;
} }
#endif #endif // ASSIMP_BUILD_NO_EXPORT