[osg-users] ref_ptr issue

2014-07-11 Thread Bram Vaessen
Hi,

I have used the osg::ref_ptr quite a lot and never had much problems with them, 
but I'm having an issue with it now.

In the main function I create a viewer (and also a DisplaySettings that is used 
by it):


Code:
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
osg::ref_ptrosg::DisplaySettings ds = new osg::DisplaySettings();
...
viewer-setDisplaySettings(ds);
...




then I also have a new class called RenderManager, who needs to viewer object 
as well. I thought this was the correct way to do it:


Code:
class RenderManager
{

osg::ref_ptrosgViewer::Viewer viewer;

osg::ref_ptrosgViewer::Viewer getViewer() { return viewer; } 
RenderManager(osg::ref_ptrosgViewer::Viewer viewer);
}

RenderManager::RenderManager(osg::ref_ptrosgViewer::Viewer):
viewer(viewer)
{
}



and I create one in main, and delete it at the end of main


Code:
RenderManager * renderManager = new RenderManager(viewer);

delete renderManager;




(I tried to simplify the code a.m.a.p.)

Now the delete seems to go well, but at the very end of main it will give a 
access violation in the destructor of ref_ptr:


world2.exe!osg::ref_ptrosgViewer::Viewer::~ref_ptrosgViewer::Viewer()  Line 
35 + 0x2e bytes C++

What did I do wrong? What is the correct way to do it? 


Thank you!

Cheers,
Bram

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] ref_ptr issue

2014-07-11 Thread Ed Stivi
Hi,
I think I also encountered this or a similar problem after the main program was 
trying to exit
eventually I ended up with a shutdown method containing the following


Code:

if(!viewer-done())
{
viewer-setDone(true);
}

// avoid circular references
viewer-getCamera()-setFinalDrawCallback(NULL);
if (!offScreen) {
osgViewer::View::EventHandlers eventHandlers = 
viewer-getEventHandlers();
eventHandlers.clear();
}

osgViewer::ViewerBase::Windows wins;
viewer-getWindows(wins);
for(int i=wins.size()-1; i=0; i--)
{
wins.at(i)-close();
}




Not sure it's the right way but some/all of it may solve out the error
try using it in renderManager's destructor
Good luck

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] ref_ptr issue

2014-07-11 Thread Bram Vaessen
Thanks, your input led me to look at the gui event handler, and it turned out 
that one of my own classes that I made long ago (an input handler) was derived 
from an OSG class, but didn't use ref_ptr somewhere for that, and that messed 
it up somehow. 
fixed now :)

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org