From 3808b298d1c5076daeb9d7644dc40b5038fb349c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 Aug 2018 19:23:17 +0100 Subject: [PATCH] Fixed memory leak associated with VertexArrayStte objects not getting released on destruction of Geometry/Drawables. --- src/osg/Drawable.cpp | 28 +++++++++++++++++++++++----- src/osg/Geometry.cpp | 5 +---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index d6c84e2ee..5c2b5551b 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -256,7 +256,7 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): Drawable::~Drawable() { - dirtyGLObjects(); + Drawable::releaseGLObjects(); } osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const @@ -340,7 +340,26 @@ void Drawable::releaseGLObjects(State* state) const } else { - const_cast(this)->dirtyGLObjects(); + #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE + for(unsigned int i=0;i<_globjList.size();++i) + { + if (_globjList[i] != 0) + { + Drawable::deleteDisplayList(i,_globjList[i], getGLObjectSizeHint()); + _globjList[i] = 0; + } + } + #endif + + for(unsigned int i=0; i<_vertexArrayStateList.size(); ++i) + { + VertexArrayState* vas = _vertexArrayStateList[i].get(); + if (vas) + { + vas->release(); + _vertexArrayStateList[i] = 0; + } + } } } @@ -434,9 +453,8 @@ void Drawable::setUseVertexBufferObjects(bool flag) void Drawable::dirtyGLObjects() { - unsigned int i; #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE - for(i=0;i<_globjList.size();++i) + for(unsigned int i=0;i<_globjList.size();++i) { if (_globjList[i] != 0) { @@ -446,7 +464,7 @@ void Drawable::dirtyGLObjects() } #endif - for(i=0; i<_vertexArrayStateList.size(); ++i) + for(unsigned int i=0; i<_vertexArrayStateList.size(); ++i) { VertexArrayState* vas = _vertexArrayStateList[i].get(); if (vas) vas->dirty(); diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 162f8a545..4c58ea069 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -82,10 +82,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): Geometry::~Geometry() { - // do dirty here to keep the getGLObjectSizeHint() estimate on the ball - dirtyGLObjects(); - - // no need to delete, all automatically handled by ref_ptr :-) + Geometry::releaseGLObjects(); } #define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0)