All,

I have an application that does off screen rendering on Windows using
OSG 2.6 to capture screen shots...   We had the need to do 10's of 1000s
of runs.  Unfortunately (on our initial attempt) we were not able to get
even a 1,000 runs because of a memory leak.   We exhaustively searched
our code to figure what we were doing wrong.  We narrowed the leak down
to a call to osg::GraphicsContext::createGraphicsContext.   Debugging
into OSG, I found the problem to be in the osgViewer library.  The
TemporaryWindow's classes call to wglDeleteContext had been commented
out as shown below.... There is a wglCreateContext call in the
TemporaryWindow::create method but no corresponding wglDeleteContext... 

void TemporaryWindow::kill()
{
    if (_context)
    {
        // mew 2005-05-09 commented out due to crashes.
        // possible causes are unsafe destructor ordering, or context
already
        // deleted by window deletion; see:
        //
http://openscenegraph.org/pipermail/osg-users/2005-May/052753.html
        // wglDeleteContext(_context);
        _context = 0;
    }
.............

}

Uncommenting this line (i.e. wglDeleteContext(_context); ) fixed our
memory leak.  I did not experience any crashes as the comment indicates.
That's not to say that you won't experience the same thing 'mew' did in
2005 but wanted to share what I found nonetheless.  This would probably
not be very noticeable if you only ever create one device context but
the code I have creates a new context for each screen capture and the
leak is painfully obvious under those circumstances.   If I hadn't found
it, my next step was to change the code to only create one device
context.  Which I think would definitely be a better approach.  But I
knew there was a memory leak somewhere and now that I found it I wanted
to share.  If it makes a difference, I checked the trunk on the latest
OSG code and this code is still the same.  Obviously you would never see
this bug either if you were only running on Linux.

Thanks,

Dan
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to