[osg-users] Forcing a scene to rebind textures

Philippe Renon philippe_renon at yahoo.fr
Mon May 11 14:40:04 PDT 2015


robertosfield wrote:
> Hi Philippe,
> Is there any chance your application is caching a subgraph that isn't
> attached to the view/contexts that are destroyed so are effectively
> hidden by the releaseGLObjects() operation?   If you re-attach such a
> subgraph to a new context it's handles to GL objects will all still be
> there but won't be valid.
> 
> If you do cache subgraphs in this way then you need to call
> rootnode->releaseGLObjects(); on it prior to deleting the context, or
> call releaseGLObjectse() afterwards then osg::discardAllGLObjects();
> 


Thank Robert, 
I think you are pointing me in the right direction.

By caching do you mean such a scenario:
1- realize and render a scene
2- detach a subgraph
3- remove View / close the GraphicsContext
4- create a new View with some scene and reattach the subgraph from step 2

Note that in my scenario (i.e. creating/detroying the "same" view+scene multiple times) the CompositeViewer itself remains the same. Views get added and removed but there is only one View at any time in that viewer (so I probably should not use CompositeViewer but I don't think it is relevant and I might need it in the future).

PS : Just tried to do the suggested cleanups after creating the view.
Code looks like this


Code:

viewer->addView(view);

// needed when adding a view a 2nd time (osg will not realize the viewer again...)
if (!viewer->isRealized()) {
    viewer->realize();
}

view->releaseGLObjects();

unsigned int contextID = view->getCamera()->getGraphicsContext()->getState()->getContextID();
osg::discardAllGLObjects(contextID);




But I still get the invalid enumerant error followed by a crash.

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








More information about the osg-users mailing list