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

Martin Siggel martinsiggel+osg at gmail.com
Mon Jul 22 11:32:55 PDT 2019

Dear Robert,

I am using OSG 3.6.4-rc3.

The only built-in shaders I am using right now are the osgText shaders:

These are automatically bound, when no other shaders are added to a text

When I don't add shaders to a geometry node, other built-in shaders seem to
get active as well. I guess these are the ones from

When I e.g. use osgText, the text will appear after starting the
application. When I go to the android main screen and then go back to the
app, the text nodes will become black rectangles. Somehow, osg seems to
reference still the "old" objects from the context before.

Still, from the log I can verify, that shaders are compiled again after
resuming to the app.

I could provide a "minimal" example if anyone is interested.


Am Mo., 22. Juli 2019 um 17:24 Uhr schrieb Robert Osfield <
robert.osfield at gmail.com>:

> HI Martin,
> I don't have any Android experience so will defer to others on the
> specifics, but one question everyone will probably have is what version of
> the OSG are you using?  When you say the OSG's "built in" shaders, which
> ones do you actually mean as there isn't any single set of "built in"
> shaders - various NodeKits provide their own shaders, and there is a
> osgUtil::ShaderGenVisitor that can create shaders for basic fixed function
> scene graph, but it's written for desktop rather that GLES2.  For GLES2
> applications one normally has to write your own shaders.
> Robert.
> On Mon, 22 Jul 2019 at 13:17, Martin Siggel <martinsiggel+osg at gmail.com>
> wrote:
>> 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
>> scratch.
>> 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
>> everything?
>> 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=11270
>> http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number
>> 4.)
>> Best regards,
>> Martin
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Dr. Martin Siggel
Neusser Straße 257
50733 Köln
Phone: 0178 6729772
martinsiggel at googlemail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20190722/e95dd604/attachment.html>

More information about the osg-users mailing list