Fixed potential memory leak
This commit is contained in:
parent
7f99182c04
commit
ce7c37851b
@ -208,26 +208,24 @@ void VertexData::readTriangles( PlyFile* file, const int nFaces )
|
|||||||
|
|
||||||
ply_get_property( file, "face", &faceProps[0] );
|
ply_get_property( file, "face", &faceProps[0] );
|
||||||
|
|
||||||
//triangles.clear();
|
|
||||||
//triangles.reserve( nFaces );
|
|
||||||
if(!_triangles.valid())
|
if(!_triangles.valid())
|
||||||
_triangles = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
|
_triangles = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);
|
||||||
if(!_quads.valid())
|
|
||||||
_quads = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
|
|
||||||
|
|
||||||
|
if(!_quads.valid())
|
||||||
|
_quads = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS);
|
||||||
|
|
||||||
|
|
||||||
|
const char NUM_VERTICES_TRIANGLE(3);
|
||||||
|
const char NUM_VERTICES_QUAD(4);
|
||||||
|
|
||||||
// read the faces, reversing the reading direction if _invertFaces is true
|
// read the faces, reversing the reading direction if _invertFaces is true
|
||||||
for( int i = 0 ; i < nFaces; i++ )
|
for( int i = 0 ; i < nFaces; i++ )
|
||||||
{
|
{
|
||||||
ply_get_element( file, static_cast< void* >( &face ) );
|
ply_get_element( file, static_cast< void* >( &face ) );
|
||||||
MESHASSERT( face.vertices != 0 );
|
if (face.vertices)
|
||||||
if( (unsigned int)(face.nVertices) > 4 )
|
{
|
||||||
|
if (face.nVertices == NUM_VERTICES_TRIANGLE || face.nVertices == NUM_VERTICES_QUAD)
|
||||||
{
|
{
|
||||||
free( face.vertices );
|
|
||||||
throw MeshException( "Error reading PLY file. Encountered a "
|
|
||||||
"face which does not have three or four vertices." );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned short index;
|
unsigned short index;
|
||||||
for(int j = 0 ; j < face.nVertices ; j++)
|
for(int j = 0 ; j < face.nVertices ; j++)
|
||||||
{
|
{
|
||||||
@ -237,10 +235,11 @@ void VertexData::readTriangles( PlyFile* file, const int nFaces )
|
|||||||
else
|
else
|
||||||
_triangles->push_back(face.vertices[index]);
|
_triangles->push_back(face.vertices[index]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// free the memory that was allocated by ply_get_element
|
// free the memory that was allocated by ply_get_element
|
||||||
free( face.vertices );
|
free( face.vertices );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user