[osg-users] Android: Survive Context Loss without complete reinitialization

Chris Djali krizdjali at gmail.com
Tue Jul 23 17:11:24 PDT 2019


You can't release objects that belong to a destroyed context, so you definitely need to call all the releaseGLObjects methods before the context is destroyed. You shouldn't need to call it on the root node provided the root node is still attached to the viewer when the viewer and context are destroyed, as the normal viewer does this for you.

You need to give the state associated with the context that's being destroyed if you just want to clear GL objects for that context. If you're fine deleting things from every context (e.g. because you've only got one context or destroy them all at once) you can just pass a null pointer, and it'll do it for all contexts.

flushAllDeletedGLObjects gets called automatically unless you're using a weird viewer (which is possible given that you're using Android, but I'd guess it isn't happening).

If I were in your situation, if you're loading fonts from files, I'd try calling releaseGLObjects on the object cache (osgDB::Registry::instance()->getObjectCache()->releaseGLObjects();) right before the context is closed, and if you're letting OSG use its default font, I'd do the default font instead (osgText::Font::getDefaultFont()->releaseGLObjects();). If either of these helps, then the problem is what I think it is. I've not looked at the Android examples, so I don't know where you'd put the call, though.


Read this topic online here:

More information about the osg-users mailing list