浏览代码

B3DImporter: Store meshes in unique_ptr

Turo Lamminen 7 年之前
父节点
当前提交
f1707e920d
共有 2 个文件被更改,包括 6 次插入5 次删除
  1. 5 4
      code/B3DImporter.cpp
  2. 1 1
      code/B3DImporter.h

+ 5 - 4
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<aiMesh> 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;j<node->mNumMeshes;++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<unsigned int>(_meshes.size());
-    scene->mMeshes=to_array( _meshes );
+    scene->mMeshes = unique_to_array( _meshes );
 
     //animations
     if( _animations.size()==1 && _nodeAnims.size() ){

+ 1 - 1
code/B3DImporter.h

@@ -123,7 +123,7 @@ private:
     std::vector<Vertex> _vertices;
 
     std::vector<aiNode*> _nodes;
-    std::vector<aiMesh*> _meshes;
+    std::vector<std::unique_ptr<aiMesh> > _meshes;
     std::vector<aiNodeAnim*> _nodeAnims;
     std::vector<std::unique_ptr<aiAnimation> > _animations;
 };