our team is currently facing a strage problem when deleting a osgTerrain instance loaded from a geotiff heightmap. When we delete an instance of osgTerrain, is damages the Qt OpenGL state. All widgets rendered within opengl canvas (by QPainter) gets crazy (totally non functional, qt starts rendering garbage). But when we recreate the terrain right after deleting it, the Qt state get restored (in that case the SO give us the same memory are by pure luck, since a shorte period of time has passed and the old memory are is still available).

One theory is that some point of Qt memory and osgTerrain memory is somehow being shared (due to an memory invasion or some other reason). When osgTerrain deletes its contents and tiles, it affects somehow other parts of program memory.

I´ve read some issues with osgTerrain tile destruction, but I have never seen any patches to fix them. So, I thing that this maybe related to the same issues.. (possibly)...

Does any one know if there is any really known issue with osgTerrain destructor and/or whether there is any solution to it? Even a temporay one..

Robert once said that using DatabasePager::setDeleteRemovedSubgraphsInDatabaseThread(false)
should suppress a double delete problem. But I could find how to apply this line of code since I couldnt find DatabasePager instance....

Our app get in trouble when we delete osgTerrain instances and we really need that! Thank you in advance!

The big question that pops up with your usage case is just exactly are you deleting the osgTerrain objects?

You never delete nodes directly, simply unrefering them and let ref counting handling do the clean up as required.

Robert.

On 28 November 2013 15:26, Pablo Carneiro Elias < (

Only registered users can see emails on this board!Get registred or enter the forums!

)> wrote:

Quote:

Hi all,

our team is currently facing a strage problem when deleting a osgTerrain instance loaded from a geotiff heightmap. When we delete an instance of osgTerrain, is damages the Qt OpenGL state. All widgets rendered within opengl canvas (by QPainter) gets crazy (totally non functional, qt starts rendering garbage). But when we recreate the terrain right after deleting it, the Qt state get restored (in that case the SO give us the same memory are by pure luck, since a shorte period of time has passed and the old memory are is still available).

One theory is that some point of Qt memory and osgTerrain memory is somehow being shared (due to an memory invasion or some other reason). When osgTerrain deletes its contents and tiles, it affects somehow other parts of program memory.

I´ve read some issues with osgTerrain tile destruction, but I have never seen any patches to fix them. So, I thing that this maybe related to the same issues.. (possibly)...

Does any one know if there is any really known issue with osgTerrain destructor and/or whether there is any solution to it? Even a temporay one..

Robert once said that using DatabasePager::setDeleteRemovedSubgraphsInDatabaseThread(false)
should suppress a double delete problem. But I could find how to apply this line of code since I couldnt find DatabasePager instance....

Our app get in trouble when we delete osgTerrain instances and we really need that! Thank you in advance!

Only registered users can see emails on this board!Get registred or enter the forums!

)> wrote:

Quote:

well, I am sure I am not deleting the node. We have a osg::ref_ptr<osg::Node> pointer to the osgTerrain instance. And by 'delete' the terrain I actually mean setting the smart pointer to zero.

OK, so you are unrefering the node. In what context is this unrefereing? Is the node not part of the scene graph that is attached to the viewer? Are you holding a reference to it in your application?

Normally when you are using a paged database you never need to keep references around to the nodes in the scene graph, instead you just let the DatabasePager expire subgraphs as required.

As for the DatabasePager instance, the osgViewer::View class has a getDatabasePager() method, so just do viewer.getDatabasePager() or view.getDatabasePager(). I just takes a quick search of the headers to find this method.

I´ve tried the databasepage setting.. no success.. Its a very strange problem.... Its deterministic: the destruction of terrain messes up the QPainter state. I am rendering FPS and some other infos using QPainter within QGLWidget as PaintDevice. The destruction of the terrain makes QPainter draw garbage and sometimes not render anything! Very strange. If I then create the terrain again, every thing backs to normal (!!).. I am using QGLWidget as opengl context holder and osgViewer::GraphicsWindowEmbedded to create a contextless window. So QT has the opengl context. The strange thing is that all other models in the scene keep being rendered fine (so its not opengl state problem I guess). I also tried to put glPushAttrib(GL_ALL_ATTRIBS_BIT)/glPopAttrib before/after QPainter calls and also cleaning up ogl matrices... nothing yield any results...

I don´t know if you can give me any clue about any possible theoretical problem that may be hapening here...

It sounds like an issue with OpenGL state management. Personally I'd avoid using Qt for any OpenGL work and keep OpenGL the domain of the OSG's graphics context. I'd also use of GrpahicsWindowEmbedded for anything other than very limited use applications.

The OSG has pretty decent text support and plenty of OSG example that illustrate how to do text on a hud for things like FPS etc, there really should be little need for using Qt for this. See the osghud example for inspiration.

Robert.

On 28 November 2013 16:31, Pablo Carneiro Elias < (

Only registered users can see emails on this board!Get registred or enter the forums!

)> wrote:

Quote:

Thanks Robert,

I´ve tried the databasepage setting.. no success.. Its a very strange problem.... Its deterministic: the destruction of terrain messes up the QPainter state. I am rendering FPS and some other infos using QPainter within QGLWidget as PaintDevice. The destruction of the terrain makes QPainter draw garbage and sometimes not render anything! Very strange. If I then create the terrain again, every thing backs to normal (!!).. I am using QGLWidget as opengl context holder and osgViewer::GraphicsWindowEmbedded to create a contextless window. So QT has the opengl context. The strange thing is that all other models in the scene keep being rendered fine (so its not opengl state problem I guess). I also tried to put glPushAttrib(GL_ALL_ATTRIBS_BIT)/glPopAttrib before/after QPainter calls and also cleaning up ogl matrices... nothing yield any results...

I don´t know if you can give me any clue about any possible theoretical problem that may be hapening here...

the line 1761 is a call do glDrawElements: qt is trying to use drawelements to draw qpainter stuff... which suggests that maybe some vbo index that Qt is trying to use is invalid. I have now a theory.. For some reason, when the terrain is destroyed, the Qt vbo is being destroyed by the terrain.

I dont know how it might happen, its just a theory, but it would explain a lot:

- First of all, when the terrain is destroyed , the qt vbo gets destroyed and qt starts rendering an invalid vbo which produces strange geometry, what explains the strange things in screen rendered by qpainter

- Secondly, when the terrain is created once again, the vbo is then recreated (since the vbo index is now free, opengl recreates it). Since the vbo in now valid again, qt is able to render properly again..

This theory explains very well the problem I am facing here. The only problem is that I habe no clue if there is really a problem in vbo management within osgTerrain... Do you know any source or part of code that might be causing something like this? If you point me anything I can debug my self using osg project here..

I think I confirm the problem. I´ve created a visitor that disables VBO in all geodes of the terrain, right after loading it. Without vbo, everything works perfectly.. no bug in qt qpainter rendering! I am able to destroy the terrain without any issues!

So, its possible that osg terrain has some issue with vbo management. I dont know if the osg philosophy is to take over the ogl context, but in my opinion, if it is really some vbo management issue, I think it would be good for osg to cooperate with other subsystems using ogl context properly, since there are many complementary libraries that can be used with osg using the same context.

I think I confirm the problem. I´ve created a visitor that disable VBO in all geodes of the terrain, right after loading it. Without vbo, everything works perfectly.. not bug in qt! I am able to destroy the terrain without any issues!

So, its possible that osg terrain has some issue with vbo management. I dont know if the osg philosophy is to take over the ogl context, but in my opinion, if it is really some vbo management issue, I think it would be good for osg to cooperate with other subsystems using ogl context properly, since there are many complementary libraries that can be used with osg using the same context.

HI Pablo,
There isn't a bug in the OSG that you need to chase after, the bug is in the integration in your application between Qt + OSG. If there is an issue with VBO usage on the OSG side there there is clearly state leakage from the OSG side to the Qt that your glue layer will need to deal with. This state leakage is purely state being set to on or OFF by the OSG and not being reset, while the Qt GL code assumes that particular state is set to something but it's not so the bug come about.

If you want to go ahead an integrate against advice then fine but you'll need to learn more about OpenGL state and what is being set by the OSG and Qt.

It worked, but the terrain got very strange (dont understand why.. it got tiled with low resolution... )

It seems just strange to me the solution "do not use two ogl systems at once, only one or another...", since ogl is created as a global shared context in fact to allow such easy integration... . But in the end I think I will be able to make some working integration here... ;/

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