From 1aed63afb73a83fbfd2bb246f54f2110471aa724 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 6 Feb 2018 19:13:54 +0200 Subject: [PATCH] OpenGEX: Replace another raw pointer with vector to fix a memory leak --- code/OpenGEXImporter.cpp | 10 +++------- code/OpenGEXImporter.h | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index a2844ccdf..dac8299c5 100644 --- a/code/OpenGEXImporter.cpp +++ b/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; } diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index eedb84375..ad331d8e6 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -147,8 +147,7 @@ private: std::vector m_vertices; size_t m_numColors; aiColor4D *m_colors; - size_t m_numNormals; - aiVector3D *m_normals; + std::vector m_normals; size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; aiVector3D *m_textureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];