From f1707e920d9b0534757326dd5786e44774eae6a3 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 18:54:41 +0200 Subject: [PATCH] B3DImporter: Store meshes in unique_ptr --- code/B3DImporter.cpp | 9 +++++---- code/B3DImporter.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index b3a01c79c..d764bd530 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -400,8 +400,7 @@ void B3DImporter::ReadTRIS( int v0 ){ Fail( "Bad material id" ); } - aiMesh *mesh=new aiMesh; - _meshes.push_back( mesh ); + std::unique_ptr mesh(new aiMesh); mesh->mMaterialIndex=matid; mesh->mNumFaces=0; @@ -429,6 +428,8 @@ void B3DImporter::ReadTRIS( int v0 ){ ++mesh->mNumFaces; ++face; } + + _meshes.emplace_back( std::move(mesh) ); } // ------------------------------------------------------------------------------------------------ @@ -635,7 +636,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ aiNode *node=_nodes[i]; for( size_t j=0;jmNumMeshes;++j ){ - aiMesh *mesh=_meshes[node->mMeshes[j]]; + aiMesh *mesh = _meshes[node->mMeshes[j]].get(); int n_tris=mesh->mNumFaces; int n_verts=mesh->mNumVertices=n_tris * 3; @@ -708,7 +709,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ //meshes scene->mNumMeshes= static_cast(_meshes.size()); - scene->mMeshes=to_array( _meshes ); + scene->mMeshes = unique_to_array( _meshes ); //animations if( _animations.size()==1 && _nodeAnims.size() ){ diff --git a/code/B3DImporter.h b/code/B3DImporter.h index b283cfab6..ef36c4618 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -123,7 +123,7 @@ private: std::vector _vertices; std::vector _nodes; - std::vector _meshes; + std::vector > _meshes; std::vector _nodeAnims; std::vector > _animations; };