Fixed memory leak associated with VertexArrayStte objects not getting released on destruction of Geometry/Drawables.

This commit is contained in:
Robert Osfield 2018-08-16 19:23:17 +01:00
parent ed13576d03
commit 3808b298d1
2 changed files with 24 additions and 9 deletions

View File

@ -256,7 +256,7 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
Drawable::~Drawable() Drawable::~Drawable()
{ {
dirtyGLObjects(); Drawable::releaseGLObjects();
} }
osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const
@ -340,7 +340,26 @@ void Drawable::releaseGLObjects(State* state) const
} }
else else
{ {
const_cast<Drawable*>(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() void Drawable::dirtyGLObjects()
{ {
unsigned int i;
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE #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) if (_globjList[i] != 0)
{ {
@ -446,7 +464,7 @@ void Drawable::dirtyGLObjects()
} }
#endif #endif
for(i=0; i<_vertexArrayStateList.size(); ++i) for(unsigned int i=0; i<_vertexArrayStateList.size(); ++i)
{ {
VertexArrayState* vas = _vertexArrayStateList[i].get(); VertexArrayState* vas = _vertexArrayStateList[i].get();
if (vas) vas->dirty(); if (vas) vas->dirty();

View File

@ -82,10 +82,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
Geometry::~Geometry() Geometry::~Geometry()
{ {
// do dirty here to keep the getGLObjectSizeHint() estimate on the ball Geometry::releaseGLObjects();
dirtyGLObjects();
// no need to delete, all automatically handled by ref_ptr :-)
} }
#define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0) #define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0)