diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 604cfca0d..348deaf0e 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -256,8 +256,28 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): Drawable::~Drawable() { - _stateset = 0; - Drawable::releaseGLObjects(); + // clean up display lists if assigned, for the display lists size we can't use glGLObjectSizeHint() as it's a virtual function, so have to default to a 0 size hint. + #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE + for(unsigned int i=0;i<_globjList.size();++i) + { + if (_globjList[i] != 0) + { + Drawable::deleteDisplayList(i,_globjList[i], 0); // we don't know getGLObjectSizeHint() + _globjList[i] = 0; + } + } + #endif + + // clean up VertexArrayState + for(unsigned int i=0; i<_vertexArrayStateList.size(); ++i) + { + VertexArrayState* vas = _vertexArrayStateList[i].get(); + if (vas) + { + vas->release(); + _vertexArrayStateList[i] = 0; + } + } } osg::MatrixList Drawable::getWorldMatrices(const osg::Node* haltTraversalAtNode) const @@ -319,6 +339,7 @@ void Drawable::releaseGLObjects(State* state) const // current OpenGL context. unsigned int contextID = state->getContextID(); + #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE if (_useDisplayList) { // get the globj for the current contextID. @@ -331,6 +352,7 @@ void Drawable::releaseGLObjects(State* state) const globj = 0; } } + #endif VertexArrayState* vas = contextID <_vertexArrayStateList.size() ? _vertexArrayStateList[contextID].get() : 0; if (vas) diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index fe6f65bb6..ebdb8bafe 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -82,22 +82,17 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): Geometry::~Geometry() { - _stateset = 0; - -#if 1 - // use the destructors to automatically handle GL object clean up when the array/primtives ref count goes to 0 - _primitives.clear(); - _vertexArray = 0; - _normalArray = 0; - _colorArray = 0; - _secondaryColorArray = 0; - _fogCoordArray = 0; - _texCoordList.clear(); - _vertexAttribList.clear(); -#else - // original clean up that cleans up GL objects regardless of any sharing of arrays/primitives - Geometry::releaseGLObjects(); -#endif + // clean up display lists if assigned, and use the GLObjectSizeHint() while prior to it being invalidated by the automatic clean up of arrays that will invalidate the getGLObjectSizeHint() value. + #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 } #define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0)