Hi Robert

right now is a little difficult to create a simple example of the issue casue 
the project has grown a lot and right now we have a lot of time pressure and 
can´t spend time making an example

what i can do is to copy/paste the main methods of the classes involved, i´ve 
deleted a lot of the code in order to make it easier to read

reading code written by other person is a little painful and i don´t pretend 
that you read all the code, but right now i can´t do anything more... don´t 
know if that helps. Anyway, here it goes

brief explanation of the code:

right now we have a class navigator which is a window that contains the opengl 
canvas (wxglcanvas), the window itself (wxframe) and the osgViewer::viewer

we also have a single scene for the whole app which is a singleton pattern 
containing the root node, and finally we have an navigator manager who controls 
all the navigators. i´ll list the navigator constructor and destructor and the 
addnavigator and deletenavigator methods of navigator manager

NAVIGATOR CONSTRUCTOR

OsgNavigator::OsgNavigator(wxMDIParentFrame *parent_frame)
{
    //create the frame    
    frame = new OsgNavigatorWxFrame(parent_frame, wxString(_T("Navigator")));
        
    //create the canvas and link it to the frame
    gl_canvas = new OsgNavigatorWxGLCanvas(frame, wxID_ANY, wxDefaultPosition, 
wxSize(256, 256));

    //create the osgviewer and link it to the canvas
    osg_viewer = new osgViewer::Viewer;
    osg_viewer->getCamera()->setGraphicsContext(gl_canvas);
    osg_viewer->getCamera()->setViewport(0,0,256,256);
        
    #ifdef NDEBUG //only in release mode. Strange breakpoints happen if running 
in debug
    osg_viewer->setThreadingModel(osg_viewer->suggestBestThreadingModel());
    #endif
    
    //get the scene (singleton pattern)
    cwviewer::IScene *app_scene = cwviewer::ApplicationScene::GetInstance();
    osg::ref_ptr<osg::Node> scene = (osg::Node *) app_scene->GetSceneData();
    
    //link the scene to the viewer
    osg_viewer->setSceneData(scene.get());

    cwviewer::ApplicationScene::FreeInstance();
    
    //link the frame to the navigator and the viewer
    frame->SetViewer(osg_viewer);
    frame->SetNavigator(this);

    //show the frame
    frame->Show(true);
}

OsgNavigator::~OsgNavigator(void)
{
    //the osg_viewer needs to be deleted before the frame to avoid problems
    //delete osg_viewer;
    frame->MSWDestroyWindow();
}

OSGNAVIGATORMANAGER

OsgNavigatorManager::OsgNavigatorManager(void)
{
    navigator_id = 0;
    osg_composite_viewer = new osgViewer::CompositeViewer();
    dbp = NULL;
}

void OsgNavigatorManager::AddNavigator(wxMDIParentFrame *parent_frame)
{
    OsgNavigator* new_navigator = new OsgNavigator(parent_frame);
    osg_composite_viewer->addView((osgViewer::Viewer *) 
new_navigator->GetViewer());

    new_navigator->SetNavigatorManager(this);
    navigator_id++;
    
    navigator_vector.push_back(new_navigator);

    //get the databasepager
    if (dbp == NULL)
        dbp = ((osgViewer::Viewer *) 
new_navigator->GetViewer())->getDatabasePager();
}

void OsgNavigatorManager::DeleteNavigator(unsigned int navigator_id)
{
    //deletes a navigator from the navigator vector
    std::vector<OsgNavigator *>::iterator i;
    OsgNavigator *n;
    osgDB::DatabasePager *new_dbp = NULL;

    //make a copy of the dbp for not loosing it when we remove the viewer
    //this shouldn´t happen, maybe an OSG bug or something we´re not doing ok...
    new_dbp = dbp->clone();

    for(i=navigator_vector.begin(); i!=navigator_vector.end(); i++)
    {
        n = *i;
        if (n->GetID() == navigator_id)
        {
            osg_composite_viewer->removeView(n->GetViewer());
            delete n;
            navigator_vector.erase(i);

            //assing our copy of the dbp to the rest of the viewers
            for (unsigned int i=0; i < osg_composite_viewer->getNumViews(); i++)
                osg_composite_viewer->getView(i)->setDatabasePager(new_dbp);
                    
            dbp = new_dbp;
            
            return;
        }
    }
}

OsgNavigatorManager::~OsgNavigatorManager(void)
{
    //first: stop all the threads    
    for (unsigned int i=0; i < osg_composite_viewer->getNumViews(); i++)
    {
        ((osgViewer::Viewer *) 
osg_composite_viewer->getView(i))->stopThreading();
    }

    //deleting the composite viewer all the associated viewers are deleted
    delete osg_composite_viewer;

    //free all the navigators
    while (!navigator_vector.empty())
    {
        delete navigator_vector.back();
        navigator_vector.pop_back();
    }
}

> Date: Wed, 7 Nov 2007 13:37:20 +0000
> From: [EMAIL PROTECTED]
> To: osg-users@lists.openscenegraph.org
> Subject: Re: [osg-users] databasepageloader and composite viewer
> 
> Hi David,
> 
> You shouldn't need to clone the DatabasePager.  osgViewer is setup so
> that the Scene object manages the scene graph and the database pager
> assocaited with that scene graph.  There is one Scene object per scene
> graph, and multiple views should share the same Scene instance if
> there share the same scene graph.  Virtue of this sharing the Scene
> shouldn't go out of scope while at lest on View still references, and
> neither should its associated DatabasePager go out of scope either.
> 
> To solve this properly it'll most likely require a few tweaks to
> osgViewer to handle this situation better.  Could you create an simple
> example that reproduces this issue?  This could then be used as test
> bed for reproducing and finally fixing it.
> 
> Robert.
> 
> On Nov 7, 2007 12:55 PM, David _ <[EMAIL PROTECTED]> wrote:
> >
> >  Hi Robert,
> >
> > problem solved!!! :)
> >
> > for some reason the removeView from the composite viewer is killing or doing
> > something to the databasepageloader (DBP).
> >
> > no matter if we have 10 viewers and the reference count of the DBP is 10,
> > whenever we kill any viewer by calling removeview of the composite viewer,
> > the DBP stops working and sometimes is destroyed. We know this because the
> > pointer to the DBP becomes useless giving us exception faults whenever we
> > call any method out of it, but the reference count remains more than zero :S
> >
> > our solution => we did clone the DBP before calling the removeView, then
> > after the removeView we call setDataBasePager(clonedDBP) for all the
> > remaining viewers and is working now perfectly. The visual studio is not
> > reporting any memory leaks, so i guess that the previous DBP is really being
> > destroyed by the removeView call although the reference count is more than
> > 1.
> >
> > don´t know if it´s an OSG bug or if we´re not doing something ok (probably
> > the second), but it´s working fine now.
> >
> > thanks for the help
> >
> >
> > > Date: Tue, 6 Nov 2007 12:50:12 +0000
> >
> >
> > > From: [EMAIL PROTECTED]
> > > To: osg-users@lists.openscenegraph.org
> > > Subject: Re: [osg-users] databasepageloader and composite viewer
> > >
> > > Hi David,
> > >
> > > There a few too many parts in this set up for me to fully understand
> > > the ins and outs to it I'm afraid. W.r.t. memory one needs to be
> > > careful about ciruclar references i.e. the window owning the viewer vs
> > > viewer owning the window. Having the GraphicsWindowWx be handled as a
> > > proxy object might be the best way to tackle this, with the WxWidget
> > > owning the GraphicsWindowWx and the Viewer's Camera owning
> > > GraphicsWindowWx, if the WxWidget goes out of scope then the
> > > GraphicsWindowWx wouldn't but would need to be switched off.
> > >
> > > Robert.
> > >
> > > On Nov 6, 2007 12:15 PM, David _ <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hi Robert,
> > > >
> > > > i´ll explaing the process we´re following and maybe you can see if we´re
> > > > doing something wrong
> > > >
> > > > we´re using wxwidgets to manage the windows system which is composed by
> > a
> > > > MDI parent frame and many MDI child frames which all share the same
> > parent
> > > > frame.
> > > >
> > > > each MDI child frame (which is itself a new window) has it´s own openGL
> > > > canvas and it´s own osgViewer. We also have one global compositeViewer
> > for
> > > > the whole application.
> > > >
> > > > the process we follow for creating each MDI Child Window is, create the
> > new
> > > > frame, create the new openglcanvas inside the new frame, create a new
> > > > osgviewer, associate the osgviewer with the canvas using
> > > > osg_viewer->getCamera()->setGraphicsContext(gl_canvas);, call the
> > SetScene
> > > > method of the viewer to tell him which scene is going to be shown and
> > > > finally we call the addView method of the compositeViewer passing the
> > new *
> > > > viewer as a parameter
> > > >
> > > > for deleting the window we first use the
> > > > composite_viewer->removeView(viewer) and then we delete the wxWidgets
> > stuff,
> > > > no direct calls to the viewer destructor is used. Does the remoview
> > kills
> > > > the viewer??? we believe it does because we see no memory leaks when the
> > > > application closes. we´re not using a ref_ptr in the viewer because we
> > had
> > > > some problems with the deleting order of the widgets, we´ll try to find
> > a
> > > > way to use it and maybe it helps a little
> > > >
> > > > if you see something which you think is not right, please tell us
> > > >
> > > > > Date: Tue, 6 Nov 2007 11:20:57 +0000
> > > >
> > > >
> > > > > From: [EMAIL PROTECTED]
> > > > > To: osg-users@lists.openscenegraph.org
> > > > > Subject: Re: [osg-users] databasepageloader and composite viewer
> > > > >
> > > > > Hi David,
> > > > >
> > > > > I've had a quick check through View.cpp and the destructor doesn't do
> > > > > anything more than unref the Scene object that should be shared
> > > > > between each of your views, and as such shouldn't actually do anything
> > > > > to the DatabasePager directly. The same goes for
> > > > > CompositeViewer::removeView, it shouldn't change anything with the
> > > > > database pager directly.
> > > > >
> > > > > Do each of the View have their own GraphicsWindow? I wonder if this
> > > > > is where the problems stem from.
> > > > >
> > > > > Robert.
> > > > >
> > > > > On Nov 6, 2007 11:12 AM, David _ <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > Hi Robert
> > > > > >
> > > > > > we´re currently using OSG 2.2 under windows compiled with visual
> > studio
> > > > 2005
> > > > > >
> > > > > >
> > > > > > > Date: Tue, 6 Nov 2007 09:01:07 +0000
> > > > > > > From: [EMAIL PROTECTED]
> > > > > > > To: osg-users@lists.openscenegraph.org
> > > > > > > Subject: Re: [osg-users] databasepageloader and composite viewer
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > Hi David,
> > > > > > >
> > > > > > > Which version of the OSG are you using?
> > > > > > >
> > > > > > > Robert.
> > > > > > >
> > > > > > > On Nov 5, 2007 9:40 AM, David _ <[EMAIL PROTECTED]>
> > wrote:
> > > > > > > >
> > > > > > > > Hi
> > > > > > > >
> > > > > > > > We´re dealing with a MDI application with multiple views of the
> > same
> > > > > > scene,
> > > > > > > > which is composed by some pagelod islands.
> > > > > > > >
> > > > > > > > we´re using the composite viewer in order to have an independent
> > > > camera
> > > > > > in
> > > > > > > > every child window and it´s working fine. The problem comes when
> > we
> > > > want
> > > > > > to
> > > > > > > > delete one of these windows.
> > > > > > > >
> > > > > > > > For deleting a view we use the removeView method of the
> > composite
> > > > viewer
> > > > > > in
> > > > > > > > order to free the osgViewer, but, sometimes it kills the
> > > > > > databasepageloader
> > > > > > > > too which stops all the LOD switching stuff. This is not
> > happening
> > > > all
> > > > > > the
> > > > > > > > viewers, just with some of them.
> > > > > > > >
> > > > > > > > How can we avoid this (killing a view of the composite viewer
> > > > without
> > > > > > > > killing the LOD stuff)???
> > > > > > > > How can we check if the databasepageloader is gone and re-start
> > it??
> > > > > > > >
> > > > > > > > thanks in advance
> > > > > > > >
> > > > > > > > help would be really appreciated
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > ________________________________
> > > > > > > > Express yourself instantly with MSN Messenger! MSN Messenger
> > > > > > > >
> > > > > > > > _______________________________________________
> > > > > > > > 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
> > > > > >
> > > > > > ________________________________
> > > > > > Express yourself instantly with MSN Messenger! MSN Messenger
> > > > > > _______________________________________________
> > > > > > 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
> > > >
> > > > ________________________________
> > > > Express yourself instantly with MSN Messenger! MSN Messenger
> > > > _______________________________________________
> > > > 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
> >
> > ________________________________
> > Express yourself instantly with MSN Messenger! MSN Messenger
> > _______________________________________________
> > 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

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to