Hi Brad,

I have already use same way, deleting cOSG object in OnDestroy event. But as
we know we would't be needed these fix, and can delete our object in
deconstructor. But now it's best solution to clear all thread safely.

Thanks so mcuh. Regards.

2009/2/13 Brad Huber <br...@procerusuav.com>

>  Umit,
>
>
>
> Here is the high level:
>
>
>
> My code is functionality similar to osgviewerMFC.  That is to say that I
> have the class cOSG which does my rendering and scene graph setup.  The
> problem I was having was in the class which instantiates the cOSG object.
> This class's deconstructed looked something like:
>
>
>
> class ClassA : public CWnd
>
> {
>
> …
>
> };
>
>
>
>
>
> ClassA::~ClassA()
>
> {
>
>             delete mOSG; // The instantion of cOSG
>
>             …
>
> }
>
>
>
> The problem is that when this destructor is called the window (CWnd) for
> the class is already destroyed.  Instead the deletion of mOSG must be done
> in the OnDestroy method:
>
>
>
> void ClassA::OnDestroy()
>
> {
>
>             delete mOSG;
>
> }
>
>
>
> Doing the deletion here ensures that the window hasn't been destroyed yet.
> OSG can cleanup and stop render threads prior to the CWnd getting destroyed.
>
>
>
> As far how the static render function / thread is shut down—I do EXACTLY
> the same as how it's done in the osgviewerMFC example.
>
>
>
> -Brad
>
>
>
> *From:* osg-users-boun...@lists.openscenegraph.org [mailto:
> osg-users-boun...@lists.openscenegraph.org] *On Behalf Of *Ümit Uzun
> *Sent:* Friday, February 13, 2009 7:03 AM
>
> *To:* OpenSceneGraph Users
> *Subject:* Re: [osg-users] OSG Multithreaded Viewer and Windows/MFC
> problem
>
>
>
> Hi Robert,
>
> I have known stopping viewer but I actually asked about static render
> running thread, and how should I stop it and order of stopping mechanism.
> For example I have tried much of below codes combinations but always I get
> error while shutting down the application.
>
>  _viewer->setDone(TRUE);
> Sleep(1000);
>  _viewer->stopThreading();
> Sleep(1000);
>  _endthread();
>
>  Firstly I should setDone to TRUE and then stop viewer threading and lastly
> I end the created thread for static render function. But it always give me
> error while trying to do all these operaion in destructor. But while I
> delete different place out of destructor, it is closing error-free.
>
> I mean if I delete the created object explicitly there is no problem, but
> if I delete the created object in destructor there is threading problem.
>
> Thanks so much. Regards.
>
> 2009/2/13 Robert Osfield <robert.osfi...@gmail.com>
>
> Hi Umit,
>
> The viewer.stopThreading() method will stop the threads and not return
> until all threads have been stopped.
>
> Robert.
>
>
> On Fri, Feb 13, 2009 at 6:51 AM, Ümit Uzun <umituzu...@gmail.com> wrote:
> > Hi Brad,
> >
> > Could you give more explanation please? How can you be sure the thread
> was
> > stopped and in which method?
> >
> > Regards.
> >
> > 2009/2/13 Brad Huber <br...@procerusuav.com>
> >>
> >> FYI,
> >>
> >>
> >>
> >> We spent some time debugging this and found the problem.
> >>
> >>
> >>
> >> I was making the unfortunate mistake of stopping the osg threads in a
> >> deconstructor which was called AFTER destroying the window.  Apparently
> OSG
> >> does not gracefully shut down threads and such if the window is pulled
> out
> >> from under it.
> >>
> >>
> >>
> >> The fix was to make sure that stopping threading and shutting down the
> >> viewer was all down BEFORE the window was made invalid.
> >>
> >>
> >>
> >> Hope this helps someone else.
> >>
> >>
> >>
> >> Thanks
> >>
> >> -Brad
> >>
> >>
> >>
> >> From: osg-users-boun...@lists.openscenegraph.org
> >> [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Ümit
> Uzun
> >> Sent: Thursday, February 12, 2009 3:35 AM
> >> To: OpenSceneGraph Users
> >> Subject: Re: [osg-users] OSG Multithreaded Viewer and Windows/MFC
> problem
> >>
> >>
> >>
> >> Hi Brad,
> >>
> >> I have same problem , but I can't resolve exactly. I only find kludge :)
> >> How can you delete your class which contains "static render" function?
> If
> >> you delete this class in destructor, it's normal getting error while
> closing
> >> your application. I have tried almost a day to resolve this undefined
> >> problem but couldn't.
> >>
> >> And My solution is; deleting class before parent destructor calling. I
> >> mean, you have renderClass and mainClass.
> >> renderClass is which contains all rendering operation and static render
> >> function.
> >> You create renderClass object from mainClass and before closing
> >> application you should delete renderClass out of mainClass destructor.
> And
> >> after that you should let the mainClass destructor to run. I hope it
> will
> >> give you smooth and error-free closing :)
> >>
> >> Regards.
> >>
> >> 2009/2/12 Brad Huber <br...@procerusuav.com>
> >>
> >> Hello,
> >>
> >>
> >>
> >> I am currently struggling with a problem that is manifesting in our MFC
> >> based app when using MultiThreading model with osg viewer.
> >>
> >>
> >>
> >> First of all when setting up the viewer in my class I used:
> >>
> >>
> >>
> >>
> >>
> mViewer->setThreadingModel(osgViewer::ViewerBase::ThreadingModel::AutomaticSelection);
> >>
> >> I also tried the default of not setting anything and the same problem
> >> happens.  If I set it to single threaded the problem disappears but
> >> obviously I don't want to run single threaded.
> >>
> >>
> >>
> >> Everything seems to run fine and then when I close the app my class
> >> destructor gets called.  The only code in the destructor is:
> >>
> >> mViewer->setDone(true);
> >>
> >> Sleep(1000);
> >>
> >> mViewer->stopThreading();
> >>
> >> Sleep(1000);
> >>
> >>
> >>
> >> Which is the same as what the example mfc code in the repository does.
> >> The sleeps were only added to see if there was a race condition problem.
> >>
> >>
> >>
> >> However when I trace in to stopThreading I see that it returns
> immediately
> >> on the first line:
> >>
> >> if (!_threadsRunning) return;
> >>
> >>
> >>
> >> As a result it doesn't kill any threads or anything else BUT there are
> >> threads still running and they show up in the debugger.
> >>
> >>
> >>
> >> Then as the app continues to close I get:
> >>
> >>
> >>
> >>
> >>
> >> Which takes me to:
> >>
> >> win32mutex.cpp line 111
> >>
> >> int Mutex::lock() {
> >>
> >>     Win32MutexPrivateData *pd =
> >>
> >>         static_cast<Win32MutexPrivateData*>(_prvData);
> >>
> >>
> >>
> >> #ifdef USE_CRITICAL_SECTION
> >>
> >>
> >>
> >>     // Block until we can take this lock.
> >>
> >>     EnterCriticalSection( &(pd->_cs) );  ß exception here!
> >>
> >>
> >>
> >>     return 0;
> >>
> >>
> >>
> >> #else
> >>
> >> …
> >>
> >>
> >>
> >> This is OSG/Openthreads stuff!  I look up the call stack and see the
> >> osgViewer::Renderer.
> >>
> >>
> >>
> >>
> >>
> >> Does anyone have any insights about why this is going on?
> >>
> >>
> >>
> >> Thanks
> >>
> >> -Brad
> >>
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> osg-users mailing list
> >> osg-users@lists.openscenegraph.org
> >>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>
> >>
> >> --
> >> Ümit Uzun
> >>
> >> _______________________________________________
> >> osg-users mailing list
> >> osg-users@lists.openscenegraph.org
> >>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>
> >
> >
> >
> > --
> > Ümit Uzun
> >
> > _______________________________________________
> > 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
>
>
>
>
> --
> Ümit Uzun
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
Ümit Uzun
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to