Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi Charles, That was the problem. The destructor of my derived class was public. I changed it to protected and to use a ref_ptr for the class and no more crashes. I'm not sure I would have ever found this bug. I wasn't even looking in that direction. So, thanks so much! Glad I could help. It's a mistake that's pretty easy to make :-) J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi David, Thanks for the response. It ended up being how I declared the destructor for my derived class as J-S pointed out. I was going down the path of when and if I needed to call releaseGLObjects() and nothing seemed to make a difference. And I'm still a little unsure of when that method should be called (or even if it should). But, fixing the destructor declaration stopped the crashes that I was seeing and I'm not explicitly calling releaseGLObjects() at all right now, on any object. chuck From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of David Spilling Sent: Friday, March 27, 2009 8:02 PM To: OpenSceneGraph Users Subject: Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables Chuck, I have had similar issues (with crashes in releaseGLObjects when views get destroyed) but can't actually recall what I did to fix them. You could try calling viewer->releaseGLObjects() before you destroy the view. (previous posts seem to suggest that this might be the right thing to do) David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi J-S, > One thing you need to be careful of when deriving classes from OSG base > classes which themselves derive from osg::Referenced ... In most cases, > the destructors of those classes should be protected. Since they're > normally protected already (as in osg::Object, osg::Drawable, etc) you > shouldn't expose them in public scope in your derived class, which > would > allow them to be (erroneously) deleted at any time by the application > instead of being deleted automatically when their ref count goes down > to 0. That was the problem. The destructor of my derived class was public. I changed it to protected and to use a ref_ptr for the class and no more crashes. I'm not sure I would have ever found this bug. I wasn't even looking in that direction. So, thanks so much! chuck ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Chuck, I have had similar issues (with crashes in releaseGLObjects when views get destroyed) but can't actually recall what I did to fix them. You could try calling viewer->releaseGLObjects() before you destroy the view. (previous posts seem to suggest that this might be the right thing to do) David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi Charles, When I referred to "destroy", what I'm doing is calling 'delete' on the classes that contain the ref_ptrs. For instance, I call delete on my view class, and in the view class' destructor, I (eventually) call delete on the drawables. So I'm in effect doing what you're saying, with the exception of the class containing the composite viewer. I'll change some code around to reflect that and see how it goes. One thing you need to be careful of when deriving classes from OSG base classes which themselves derive from osg::Referenced ... In most cases, the destructors of those classes should be protected. Since they're normally protected already (as in osg::Object, osg::Drawable, etc) you shouldn't expose them in public scope in your derived class, which would allow them to be (erroneously) deleted at any time by the application instead of being deleted automatically when their ref count goes down to 0. I've had a similar problem once, which was being caused by a double-delete. I was manually deleting a custom drawable or node (I can't remember) and then since it was still in the scene graph, it was being deleted when the viewer went out of scope too. In general, trust ref_ptr to manage anything derived from osg::Referenced. Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi J-S, When I referred to "destroy", what I'm doing is calling 'delete' on the classes that contain the ref_ptrs. For instance, I call delete on my view class, and in the view class' destructor, I (eventually) call delete on the drawables. So I'm in effect doing what you're saying, with the exception of the class containing the composite viewer. I'll change some code around to reflect that and see how it goes. Thanks. chuck > -Original Message- > From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users- > boun...@lists.openscenegraph.org] On Behalf Of Jean-Sébastien Guay > Sent: Friday, March 27, 2009 1:45 PM > To: OpenSceneGraph Users > Subject: Re: [osg-users] Problems shutting down Composite > Viewer/View/Custom drawables > > Hi Charles, > > > My attempted process to close is that I (1) set a flag on a render > thread to stop calling viewer->frame (very similar to setDone(true)); > (2) destroy the loaded drawables and free their associated libraries; > (3) destroy the view, and thus it's associated camera and graphics > context; and (4) destroy the composite viewer. I use reference > pointers in every case except for the composite viewer (although I've > tried a reference pointer for it as well, but still get the same > result). > > Just wondering, if you're using ref_ptrs, why don't you just let the > CompositeViewer's ref_ptr go out of scope (or delete the object that > has > the ref_ptr) and be done with it? That should cascade > down, destroying the views, then each view's scene graph. And if your > custom drawables do the right thing in their destructors, that should > be > taken care of too. You shouldn't have to manage destruction order > yourself. > > Perhaps I'm missing something here, but that generally just works. > > J-S > -- > __ > Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com > http://www.cm-labs.com/ > http://whitestar02.webhop.org/ > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users- > openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi Charles, My attempted process to close is that I (1) set a flag on a render thread to stop calling viewer->frame (very similar to setDone(true)); (2) destroy the loaded drawables and free their associated libraries; (3) destroy the view, and thus it's associated camera and graphics context; and (4) destroy the composite viewer. I use reference pointers in every case except for the composite viewer (although I've tried a reference pointer for it as well, but still get the same result). Just wondering, if you're using ref_ptrs, why don't you just let the CompositeViewer's ref_ptr go out of scope (or delete the object that has the ref_ptr) and be done with it? That should cascade down, destroying the views, then each view's scene graph. And if your custom drawables do the right thing in their destructors, that should be taken care of too. You shouldn't have to manage destruction order yourself. Perhaps I'm missing something here, but that generally just works. J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi all, I forgot to mention in my long-winded post that I'm using OSG 2.8.0. chuck > -Original Message- > From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users- > boun...@lists.openscenegraph.org] On Behalf Of Cole, Charles E. (LARC- > B702)[RAYTHEON TECHNICAL SERVICES COMPANY] > Sent: Friday, March 27, 2009 12:51 PM > To: OpenSceneGraph Users > Subject: [osg-users] Problems shutting down Composite > Viewer/View/Custom drawables > > Hi all, > > I've been chasing an error in my code for many, many days that I'm > hoping that someone can help me track down. I'll try to explain my > application as best I can. > > I'm using a composite viewer to load multiple views. In each view, I'm > loading a database scene (generally a TXP database) and overlaying > OpenGL nodes that I load dynamically and add as drawables to the > scenegraph. I've created classes to encapsulate the composite viewer, > view, and scene nodes. For instance, I have a class that contains a > composite viewer member variable; this class then creates multiple > "View" classes that each contain an osgViewer::View member variable. > Each view then loads scene nodes as specified in a configuration file. > These nodes are contained in separate libraries and are loaded as > drawables (I've created a class derived from osg::Drawable and > overwrite the drawImplementation method for custom drawing). > Everything works great when creating the viewer, view, nodes, and even > executing. The problem comes when I try to destroy/close the window. > > My attempted process to close is that I (1) set a flag on a render > thread to stop calling viewer->frame (very similar to setDone(true)); > (2) destroy the loaded drawables and free their associated libraries; > (3) destroy the view, and thus it's associated camera and graphics > context; and (4) destroy the composite viewer. I use reference > pointers in every case except for the composite viewer (although I've > tried a reference pointer for it as well, but still get the same > result). > > When trying to follow the above process, the application crashes in the > Node::releaseGLObjects method at line 523, if (_updateCallback.valid()) > _updateCallback.releaseGLObjects(state). > > I also noticed during a debug walkthrough that the drawables > drawImplementation method (and thus the custom drawable's own custom > drawing methods) are still being called after the render thread has > been stopped and destroyed. > > So, some of my many questions are: > > (1) Is there a preferred/required means or order for shutting down a > composite viewer (and it's child nodes)? > > (2) Separately, but possibly related ... I create a camera callback > function to update the camera position per shared memory variables. > I'd like to destroy that callback function appropriately. But, in > doing so, how do I reset the camera's callback function such that it's > not called once the custom callback function is destroyed? > > (3) What's the appropriate means of stopping the rendering? I thought > that if viewer->frame() wasn't getting called, the drawImplementation > method of the drawables would no longer be called, so I could then free > those libraries. But, unfortunately, they're still being called even > though frame() is no longer called. And thus, the libraries are trying > to be freed when the viewer is still trying to draw them. > > I am running multithreaded. I'm using VS 2008 SP1 on Windows XP and > Vista. > > If anyone has any tips, pointers, something to point me in the right > direction before I end up throwing the computer through the window, I'd > greatly appreciate it. I hope I've provided enough information. > > Thanks so much in advance. > > Chuck > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users- > openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Problems shutting down Composite Viewer/View/Custom drawables
Hi all, I've been chasing an error in my code for many, many days that I'm hoping that someone can help me track down. I'll try to explain my application as best I can. I'm using a composite viewer to load multiple views. In each view, I'm loading a database scene (generally a TXP database) and overlaying OpenGL nodes that I load dynamically and add as drawables to the scenegraph. I've created classes to encapsulate the composite viewer, view, and scene nodes. For instance, I have a class that contains a composite viewer member variable; this class then creates multiple "View" classes that each contain an osgViewer::View member variable. Each view then loads scene nodes as specified in a configuration file. These nodes are contained in separate libraries and are loaded as drawables (I've created a class derived from osg::Drawable and overwrite the drawImplementation method for custom drawing). Everything works great when creating the viewer, view, nodes, and even executing. The problem comes when I try to destroy/close the window. My attempted process to close is that I (1) set a flag on a render thread to stop calling viewer->frame (very similar to setDone(true)); (2) destroy the loaded drawables and free their associated libraries; (3) destroy the view, and thus it's associated camera and graphics context; and (4) destroy the composite viewer. I use reference pointers in every case except for the composite viewer (although I've tried a reference pointer for it as well, but still get the same result). When trying to follow the above process, the application crashes in the Node::releaseGLObjects method at line 523, if (_updateCallback.valid()) _updateCallback.releaseGLObjects(state). I also noticed during a debug walkthrough that the drawables drawImplementation method (and thus the custom drawable's own custom drawing methods) are still being called after the render thread has been stopped and destroyed. So, some of my many questions are: (1) Is there a preferred/required means or order for shutting down a composite viewer (and it's child nodes)? (2) Separately, but possibly related ... I create a camera callback function to update the camera position per shared memory variables. I'd like to destroy that callback function appropriately. But, in doing so, how do I reset the camera's callback function such that it's not called once the custom callback function is destroyed? (3) What's the appropriate means of stopping the rendering? I thought that if viewer->frame() wasn't getting called, the drawImplementation method of the drawables would no longer be called, so I could then free those libraries. But, unfortunately, they're still being called even though frame() is no longer called. And thus, the libraries are trying to be freed when the viewer is still trying to draw them. I am running multithreaded. I'm using VS 2008 SP1 on Windows XP and Vista. If anyone has any tips, pointers, something to point me in the right direction before I end up throwing the computer through the window, I'd greatly appreciate it. I hope I've provided enough information. Thanks so much in advance. Chuck ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org