소스 검색

OpenGEX: Replace another raw pointer with vector to fix a memory leak

Turo Lamminen 7 년 전
부모
커밋
1aed63afb7
2개의 변경된 파일4개의 추가작업 그리고 9개의 파일을 삭제
  1. 3 7
      code/OpenGEXImporter.cpp
  2. 1 2
      code/OpenGEXImporter.h

+ 3 - 7
code/OpenGEXImporter.cpp

@@ -223,8 +223,6 @@ static void propId2StdString( Property *prop, std::string &name, std::string &ke
 OpenGEXImporter::VertexContainer::VertexContainer()
 : m_numColors( 0 )
 , m_colors( nullptr )
-, m_numNormals( 0 )
-, m_normals( nullptr )
 , m_numUVComps()
 , m_textureCoords() {
     // empty
@@ -233,7 +231,6 @@ OpenGEXImporter::VertexContainer::VertexContainer()
 //------------------------------------------------------------------------------------------------
 OpenGEXImporter::VertexContainer::~VertexContainer() {
     delete[] m_colors;
-    delete[] m_normals;
 
     for(auto &texcoords : m_textureCoords) {
         delete [] texcoords;
@@ -861,9 +858,8 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene
             m_currentVertices.m_colors = new aiColor4D[ numItems ];
             copyColor4DArray( numItems, vaList, m_currentVertices.m_colors );
         } else if( Normal == attribType ) {
-            m_currentVertices.m_numNormals = numItems;
-            m_currentVertices.m_normals = new aiVector3D[ numItems ];
-            copyVectorArray( numItems, vaList, m_currentVertices.m_normals );
+            m_currentVertices.m_normals.resize( numItems );
+            copyVectorArray( numItems, vaList, m_currentVertices.m_normals.data() );
         } else if( TexCoord == attribType ) {
             m_currentVertices.m_numUVComps[ 0 ] = numItems;
             m_currentVertices.m_textureCoords[ 0 ] = new aiVector3D[ numItems ];
@@ -900,7 +896,7 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
         hasColors = true;
     }
     bool hasNormalCoords( false );
-    if ( m_currentVertices.m_numNormals > 0 ) {
+    if ( !m_currentVertices.m_normals.empty() ) {
         m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ];
         hasNormalCoords = true;
     }

+ 1 - 2
code/OpenGEXImporter.h

@@ -147,8 +147,7 @@ private:
         std::vector<aiVector3D> m_vertices;
         size_t m_numColors;
         aiColor4D *m_colors;
-        size_t m_numNormals;
-        aiVector3D *m_normals;
+        std::vector<aiVector3D> m_normals;
         size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
         aiVector3D *m_textureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];