//#define DEBUG_B3D
+template<typename T>
+void DeleteAllBarePointers(std::vector<T>& x)
+{
+ for(auto p : x)
+ {
+ delete p;
+ }
+}
+
+B3DImporter::~B3DImporter()
+{
+ DeleteAllBarePointers(_animations);
+}
+
// ------------------------------------------------------------------------------------------------
bool B3DImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const{
void B3DImporter::ReadBB3D( aiScene *scene ){
_textures.clear();
+
_materials.clear();
_vertices.clear();
+
_meshes.clear();
+ DeleteAllBarePointers(_nodes);
_nodes.clear();
+
_nodeAnims.clear();
+
+ DeleteAllBarePointers(_animations);
_animations.clear();
string t=ReadChunk();
class B3DImporter : public BaseImporter{
public:
+ B3DImporter() = default;
+ virtual ~B3DImporter();
virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
aiNode* newRoot = new aiNode();
newRoot->mName = pScene->mRootNode->mName;
delete pScene->mRootNode;
- pScene->mRootNode = new aiNode();
+ pScene->mRootNode = newRoot;
if (1 == pScene->mNumMeshes && !pScene->mNumLights && !pScene->mNumCameras)
{
static aiScene *createDefaultTestModel( float &opacity ) {
aiScene *scene( new aiScene );
scene->mNumMaterials = 1;
- scene->mMaterials = new aiMaterial*;
+ scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
scene->mMaterials[ 0 ] = new aiMaterial;
aiColor3D color( 1, 0, 0 );
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) );
EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) );
scene->mNumMeshes = 1;
- scene->mMeshes = new aiMesh*;
+ scene->mMeshes = new aiMesh*[scene->mNumMeshes];
scene->mMeshes[ 0 ] = new aiMesh;
scene->mMeshes[ 0 ]->mMaterialIndex = 0;
scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 );
scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 );
scene->mMeshes[ 0 ]->mNumFaces = 1;
- scene->mMeshes[ 0 ]->mFaces = new aiFace;
+ scene->mMeshes[ 0 ]->mFaces = new aiFace[scene->mMeshes[ 0 ]->mNumFaces];
scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3;
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ];
scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0;
scene->mRootNode = new aiNode;
scene->mRootNode->mNumMeshes = 1;
- scene->mRootNode->mMeshes = new unsigned int( 0 );
+ scene->mRootNode->mMeshes = new unsigned int[scene->mRootNode->mNumMeshes]{ 0 };
return scene;
}
EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) );
EXPECT_EQ( opacity, newOpacity );
}
+ delete scene;
}
#endif // ASSIMP_BUILD_NO_EXPORT
differ.showReport();
m_im->FreeScene();
+ for(unsigned int i = 0; i < expected->mNumMeshes; ++i)
+ {
+ delete expected->mMeshes[i];
+ }
+ delete[] expected->mMeshes;
+ expected->mMeshes = nullptr;
+ delete[] expected->mMaterials;
+ expected->mMaterials = nullptr;
+ delete expected;
}
TEST_F( utObjImportExport, issue1111_no_mat_name_Test ) {
scene->mMeshes[ 0 ] = mesh;
RemoveVCProcess *process = new RemoveVCProcess;
process->Execute( scene );
-}
\ No newline at end of file
+ delete scene;
+}
#include "UnitTestPCH.h"
#include <assimp/SceneCombiner.h>
#include <assimp/mesh.h>
+#include <memory>
using namespace ::Assimp;
mesh3->mName.Set( "mesh_3" );
merge_list.push_back( mesh3 );
- aiMesh *out( nullptr );
- SceneCombiner::MergeMeshes( &out, 0, merge_list.begin(), merge_list.end() );
+ std::unique_ptr<aiMesh> out;
+ aiMesh* ptr = nullptr;
+ SceneCombiner::MergeMeshes( &ptr, 0, merge_list.begin(), merge_list.end() );
+ out.reset(ptr);
std::string outName = out->mName.C_Str();
EXPECT_EQ( "mesh_1.mesh_2.mesh_3", outName );
}