[osg-submissions] Reuse of context IDs and cleanup of OpenGL resources.
Mark Sciabica
msciabica at itracs.com
Mon Apr 14 13:55:49 PDT 2008
These changes are a fix for the bug reported here:
http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2
008-January/006048.html
Briefly, the bug is that objects that allocate OpenGL resources (e.g.
textures or display lists) for a given contextID believe those objects
are still valid even after the contextID becomes invalid and then reused
by another context.
A source file is attached that reproduces the bug for display lists,
textures, and fonts. Other resource types have not been tested, although
code has been added to clean up all types that currently clean up their
deleted items caches in the GraphicsContext::close function.
The modifications were made against the 2.2.0 branch.
Summary of changes.
1. ContextData now has a list of objects using OpenGL resources for its
contextID.
2. Objects using OpenGL resources now add themselves to the above list
when they allocate such a resource, and remove themselves when they
deallocate it.
3. GraphicsContext::close deallocates the registered resources if no
other contexts are using its contextID. Calling releaseGLObjects on the
camera now seems redundant so was removed. (Exception: if the _state
member of the GraphicsContext is NULL (which it is when close() is
called more than once(and it is)) then the camera will have its
GLObjects released in ALL contexts. This seems incorrect as it
needlessly releases objects in unrelated contexts.)
4. ContextData was made an Observer of the objects in its list to avoid
dereferencing invalid pointers if those objects are destroyed without
deallocating their resources.
5. Static functions that allocate resources and manage a cache of
deleted objects were made nonstatic so they could register the object
with the context at the time the resource was allocated. They assume the
object they're called against is the object owning the resource. These
functions have also been made protected to help enforce this.
Regards,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openscenegraph.org/pipermail/osg-submissions-openscenegraph.org/attachments/20080414/e262431b/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: repro.cpp
Type: application/octet-stream
Size: 2295 bytes
Desc: repro.cpp
Url : http://lists.openscenegraph.org/pipermail/osg-submissions-openscenegraph.org/attachments/20080414/e262431b/attachment-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GLResourceCleanup.zip
Type: application/x-zip-compressed
Size: 88013 bytes
Desc: GLResourceCleanup.zip
Url : http://lists.openscenegraph.org/pipermail/osg-submissions-openscenegraph.org/attachments/20080414/e262431b/attachment-0001.bin
More information about the osg-submissions
mailing list