[osg-users] Removing objects with shared GL state from scene graph

Chris Djali krizdjali at gmail.com
Wed Jul 3 16:06:32 PDT 2019


Hi,

Turns out that it's not a font in the object cache that's causing me grief after all, but instead the static default font here: https://github.com/openscenegraph/OpenSceneGraph/blob/OpenSceneGraph-3.6/src/osgText/Font.cpp#L40. This is initialised from a GLubyte array instead of a file, so never ends up in the object cache.

I can manually call releaseGLObjects on it when a graphics context is destroyed, which solves the problem for my application, but I can provide an example of an OSG application that CodeXL says leaks stuff to prove that there's still a footgun.


Code:
int main()
{
    osgViewer::Viewer viewer;

    // Use an auto transform so the text actually faces the screen
    osg::ref_ptr<osg::AutoTransform> scene = new osg::AutoTransform();
    scene->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
    viewer.setSceneData(scene);

    osg::ref_ptr<osgText::Text> text1 = new osgText::Text();
    text1->setText("text1");
    scene->addChild(text1);

    // Display one or more frames
    viewer.setCameraManipulator(new osgGA::TrackballManipulator());
    for (int i = 0; i < 100; ++i)
        viewer.frame();

    // Remove a text node
    scene->removeChild(text1);

    // Pick which path depending on whether or not we trust all references to things to go away
    if (false)
    {
        text1->releaseGLObjects();
    }
    else
    {
        
    }

    text1 = nullptr;

    // osgText::Font::getDefaultFont::s_defaultFont still exists, so the default font isn't released

    return viewer.run();
}



As before, CodeXL is still reporting the following error:

[Image: https://cdn.discordapp.com/attachments/502999428798480387/596112745104146487/unknown.png ]

Maybe it would be a good idea for static OSG objects to all be held together in a global vector somewhere so that their GL objects can be released whenever a context is destroyed. Maybe something like that exists already and the default font just got forgotten.

Cheers,
Chris

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=76365#76365







More information about the osg-users mailing list