OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Android: Survive Context Loss without complete reinitialization


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Martin Siggel
Guest





PostPosted: Mon Jul 22, 2019 12:17 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

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=11270http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number 4.)


Best regards,
Martin

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12336

PostPosted: Mon Jul 22, 2019 3:24 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

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+ ([email]martinsiggel%[/email])> wrote:

Quote:
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=11270http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number 4.)


Best regards,
Martin


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Martin Siggel
Guest





PostPosted: Mon Jul 22, 2019 6:33 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Dear Robert,

I am using OSG 3.6.4-rc3.

The only built-in shaders I am using right now are the osgText shaders:
https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders

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

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 https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders.

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.

Martin.


Am Mo., 22. Juli 2019 um 17:24 Uhr schrieb Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:

Quote:
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+ ([email]martinsiggel%[/email])> wrote:

Quote:
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=11270http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number 4.)


Best regards,
Martin


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



--
Dr. Martin SiggelNeusser Straße 257
50733 Köln 
Phone: 0178 6729772
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12336

PostPosted: Tue Jul 23, 2019 9:03 am    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Hi Martin,


On Mon, 22 Jul 2019 at 19:33, Martin Siggel <martinsiggel+ ([email]martinsiggel%[/email])> wrote:
Quote:
I am using OSG 3.6.4-rc3.


That's from back in January so it would be worth updating to 3.6.4-rc8. 



I've done a diff between rc3 and rc8 and overall there are quite a few fixes, I couldn't see a change that would affect things for you with osgText.

Quote:
The only built-in shaders I am using right now are the osgText shaders:
https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders

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

Quote:
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 https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders.


Those shaders are related to the shader pipeline that is only part of master, they don't exist in 3.6.  If you are aren't creating your own shaders do they come with your data?  Or are you using osgUtil::ShaderGen?


Quote:
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.

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



What hardware/software Android platform are you testing with?


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



I don't personally have a Android dev environment setup, so I can't test.  I was hoping that other Android users would chip in here, unfortunately the forum has been a bit unreliable of late so perhaps this is contributing.



Cheers,
Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Martin Siggel
Guest





PostPosted: Tue Jul 23, 2019 11:15 am    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Dear Robert,

I am now on master. The problems still exist.

Quote:
Those shaders are related to the shader pipeline that is only part of master, they don't exist in 3.6.

You are right. Lets forget the inbuilt shaders. The problems occur
also with my own shaders. The only place I use the inbuilt ones are
for text nodes. Those also existed in rc3.

Quote:
Or are you using osgUtil::ShaderGen?

No.

Quote:
What hardware/software Android platform are you testing with?

I am testing it in the android emulator that comes with the Android
SDK. Additionally I also have a One Plus 3 around, which show the same
problems.

Is there any way I can help you setting up an Android Dev environment?
I am thinking of a virtual machine that I could create for testing. Or
step by step instructions, how to build OSG and the example.

But maybe lets not focus too much on android. It seems, that similar
issues also occurred with qt, when a gl context was recreated. My
question is, how to properly notify to OSG, that all shaders +
uniforms are invalid such that it recompiles them. Actually, OSG
already recompiles the shader after creating a new embedded window and
therefore increasing the context id. Maybe the old shader objects are
not disposed properly and are still attached to the stateset (just
guessing).

Unfortunately, I don't know OSG much that I can find out, what is
actually going wrong.

Martin

Am Di., 23. Juli 2019 um 11:03 Uhr schrieb Robert Osfield
<>:
Quote:

Hi Martin,

On Mon, 22 Jul 2019 at 19:33, Martin Siggel <martinsiggel+> wrote:
Quote:
I am using OSG 3.6.4-rc3.

That's from back in January so it would be worth updating to 3.6.4-rc8.

I've done a diff between rc3 and rc8 and overall there are quite a few fixes, I couldn't see a change that would affect things for you with osgText.

Quote:
The only built-in shaders I am using right now are the osgText shaders:
https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders

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

Quote:
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 https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders.

Those shaders are related to the shader pipeline that is only part of master, they don't exist in 3.6. If you are aren't creating your own shaders do they come with your data? Or are you using osgUtil::ShaderGen?

Quote:
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.

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

What hardware/software Android platform are you testing with?

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

I don't personally have a Android dev environment setup, so I can't test. I was hoping that other Android users would chip in here, unfortunately the forum has been a bit unreliable of late so perhaps this is contributing.

Cheers,
Robert.



------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12336

PostPosted: Tue Jul 23, 2019 2:50 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Hi Martin,


The osg::Node's have releaseGLObjects() that help disconnect the GLObjects from the scene graph, these get put in several backend containers for the GLObjects, that get cleaned up by a call to osg::flushAllDeletedGLObjects.  The standard viewer should be doing all this for you, but in your case you'll be using a non standard route thanks to the constraints of Android windowing.  I'm not the author of the the Android windowing example so can't comment on the specifics.  I guess there is chance there is an error at the viewer level somewhere.


As general comment, the VSG project is probably a better fit for Android than the OSG, thanks to both the Vulkan and the lightweight design/implementation of the VSG.   Under Vulkan you create most graphics objects tied to the Vulkan Instance, when a window is resized or closed/opened you have to recreate the window related objects, but other objects can be shared.  This recreation of objects happens for all platforms so it's not a Android special issue like it is for OpenGL, so it's more likely we'll be able to spot issues and debug them prior to a port to Android.


The VSG still early it's life though, so feature wise it's a long way behind the OSG right now.  It's still a moving target too, but if you don't need a wide range of OSG features then you might be able to get by with the VSG. 



Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
AnyOldName3 (Chris Djali)
User


Joined: 08 Sep 2017
Posts: 57

PostPosted: Tue Jul 23, 2019 5:23 pm    Post subject:
Reply with quote

Hi,

This is almost certainly due to one of the issues I've outlined here: http://forum.openscenegraph.org/viewtopic.php?p=76471#76471

The standard viewer definitely doesn't clean everything up that it's supposed to, as demonstrated by the examples I gave in that thread. Specifically, this example shows that the static default font isn't released: http://forum.openscenegraph.org/viewtopic.php?p=76365#76365, and this example shows that loaded fonts living in the object cache aren't released: http://forum.openscenegraph.org/viewtopic.php?p=76345#76345.

You'll need to run these examples through an OpenGL debugger like CodeXL that tells you when things aren't released.

Cheers,
Chris
Back to top
View user's profile Send private message
Martin Siggel
Guest





PostPosted: Tue Jul 23, 2019 10:18 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Dear Robert,

what is the correct order of the calls I have to made? :
a) Context detroyed
b) call releaseGLObjects. This required a state argument. Which state
do I have to put in here? Is it sufficient to call this on the root
node of my scene graph?
c) what about osg::flushAllDeletedGLObjects? Is this called automatically?

Or do I have to call releaseGlObjects BEFORE the context is destroyed?

Sorry for asking these probably stupid questions.

What would be a more standard way of doing things (on android)? Is a
context loss so exotic?

Regarding VSG: I'd really love playing around with Vulkan.
Unfortunately, two things are making me to stick to OpenGL:
1) Vulkan requires Android 8. Therefore, many phones would not be supported.
2) Not enough time to get into Vulkan at the moment :(

I actually don't need much features, so VSG might be nice in future:
- Geometry creation from own tesselations
- Edge/Line rendering
- Picking / Intersections
- Custom Shaders
- Text Nodes

Martin


------------------
Post generated by Mail2Forum
Back to top
AnyOldName3 (Chris Djali)
User


Joined: 08 Sep 2017
Posts: 57

PostPosted: Wed Jul 24, 2019 12:11 am    Post subject:
Reply with quote

Hi,

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.


Cheers,
Chris
Back to top
View user's profile Send private message
Martin Siggel
Guest





PostPosted: Wed Jul 24, 2019 1:02 pm    Post subject:
Android: Survive Context Loss without complete reinitialization
Reply with quote

Hi Chris,

thanks for pointing me to the right direction. Unfortunately, it
didn't work as expected, probably because I still don't get things
right in my head ;)

However, I found a workaround that works quite well: I simply destroy
my viewer before I get a context loss. I can still keep my scene so
everything looks as before leaving the app. When going back into the
application, I simply create a new viewer and everything works smooth
:)

Best regards,
Martin



Am Mi., 24. Juli 2019 um 03:28 Uhr schrieb Chris Djali <>:
Quote:

Hi,

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()Wink 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()Wink. 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.


Cheers,
Chris

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








------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Shared openGL Context generating Glyp... pioupiou General 0 Fri Jul 19, 2019 3:23 pm View latest post
No new posts osgQt doesn't set a context ID AnyOldName3 General 2 Tue Mar 12, 2019 6:35 pm View latest post
No new posts ~GLExtensions clears cached values fo... robertosfield Submission 0 Tue Oct 02, 2018 11:32 am View latest post
No new posts context IDs andyskinner General 41 Mon Sep 17, 2018 6:13 pm View latest post
No new posts Cross-platform examples for Linux, ma... kornerr Announcement [ANN] 6 Tue Aug 14, 2018 10:51 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP