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

Martin Siggel martinsiggel+osg at gmail.com
Mon Jul 22 05:16:47 PDT 2019

Hi @all,

I built a prototypical Android application based on your OSG GLES 2.0
example. As also users in the OSG forum pointed out, the problem with
this example application is, that is reinitialized everything, when
e.g. leaving the app, changing the screen orientation and so on.

I worked around this by just calling again
'setUpViewerAsEmbeddedInWindow' instead of creating everything from

This seems to work pretty well, but sometimes - after a EGL context
loss - the shader programs are somehow lost or invalid, resulting in a
wrong rendering. This even happens, when using OSG's default shaders.

When debugging OSG, it seems to me, that OSG tries to clean up all GL
objects - including the shaders and reinitialize everything (also
compiling the shader objects).

Still, it happens, that the shaders get invalid sometimes and I'll get
the error:

   s_glUseProgram:2041 GL error 0x501

Which basically means invalid program. Are the shader handled somehow
differently? What do I have to do, in order to properly cleanup

Does anyone of you have any example surviving correctly a context loss
e.g. due to application switch?

Here are forum entries that describe a similar problem:

http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number 4.)

Best regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20190722/bc926852/attachment.html>

More information about the osg-users mailing list