Hi Robert, > I suspect this issue is down to the Scene object being destructed > after the sceneCacheMutex and s_sceneCache are destructed
Exactly. I managed to modify osgviewer app to exhibit this problem. I just moved viewer object from local scope to global and added std::exit(0); after viewer's construction. Valgrind reports following: ==15282== Invalid read of size 4 ==15282== at 0x5A99004: pthread_mutex_lock (pthread_mutex_lock.c:50) ==15282== by 0x656E199: OpenThreads::Mutex::lock() (PThreadMutex.cpp:130) ==15282== by 0x519CECF: OpenThreads::ScopedLock<OpenThreads::Mutex>::ScopedLock(OpenThreads::Mutex&) (ScopedLock:31) ==15282== by 0x57DB40F: osgViewer::Scene::~Scene() (Scene.cpp:45) ==15282== by 0x57DB579: osgViewer::Scene::~Scene() (Scene.cpp:57) ==15282== by 0x52F486B: osg::Referenced::signalObserversAndDelete(bool, bool) const (Referenced.cpp:323) ==15282== by 0x403018: osg::Referenced::unref() const (Referenced:198) ==15282== by 0x580F250: osg::ref_ptr<osgViewer::Scene>::~ref_ptr() (in /usr/local/lib64/libosgViewerd.so.3.1.0) ==15282== by 0x57FEF7C: osgViewer::View::~View() (View.cpp:177) ==15282== by 0x581AEA8: osgViewer::Viewer::~Viewer() (Viewer.cpp:216) ==15282== by 0x581AFDF: osgViewer::Viewer::~Viewer() (Viewer.cpp:249) ==15282== by 0x52F486B: osg::Referenced::signalObserversAndDelete(bool, bool) const (Referenced.cpp:323) ==15282== by 0x403018: osg::Referenced::unref() const (Referenced:198) ==15282== by 0x4036F2: osg::ref_ptr<osgViewer::Viewer>::~ref_ptr() (in /usr/local/bin/osgviewerd) ==15282== by 0x6204820: __run_exit_handlers (exit.c:78) ==15282== by 0x62048A4: exit (exit.c:100) ==15282== by 0x402C62: main (osgviewer.cpp:48) ==15282== Address 0x92dc618 is 24 bytes inside a block of size 48 free'd ==15282== at 0x4C27FF2: operator delete(void*) (vg_replace_malloc.c:387) ==15282== by 0x656E267: OpenThreads::PThreadMutexPrivateData::~PThreadMutexPrivateData() (PThreadMutexPrivateData.h:38) ==15282== by 0x656E131: OpenThreads::Mutex::~Mutex() (PThreadMutex.cpp:115) ==15282== by 0x6204820: __run_exit_handlers (exit.c:78) ==15282== by 0x62048A4: exit (exit.c:100) ==15282== by 0x402C62: main (osgviewer.cpp:48) So, the mutex is already destructed when Scene is about to be destroyed. I guess the user should have the right to place osg::ref_ptr< osgViewer::Viewer > viewer; to the global scope, so the issue needs to be fixed. Ideas? Do you think moving static s_sceneCacheMutex and s_sceneCache of Scene.cpp into the global scope would be the proper fix? John On Monday 12 of March 2012 10:25:07 Robert Osfield wrote: > Hi John, > > I suspect this issue is down to the Scene object being destructed > after the sceneCacheMutex and s_sceneCache are destructed as both of > these are constructed till after the first Scene object is > constructed. To force these objects to be constructed first I think > it is probably best to move the static s_sceneCacheMutex and > s_sceneCache into the global scope to ensure they get created before > the first Scene object ever gets created. > > Robert. > > On 12 March 2012 10:03, PC John <[email protected]> wrote: > > Hi, > > > > I found a deadlock in Scene.cpp. The problem exhibits itself when > > calling > > std::exit() instead of standard way of terminating of the application. > > > > The deadlock is seen on Windows only. On Linux, I get sigsegv or, at > > least, valgrind gives me info about using already freed memory. > > > > After the investigation, I found that the problem is using of static > > variables in getSceneCache() and getSceneCacheMutex() in Scene.cpp. The > > destructors of these static variables are registered by the compiler > > (gcc) using atexit() approach. (I could not believed it and made > > additional tests, but all the same.) As a result, the mentioned > > variables are destructed too early and before all global variables, > > resulting sigsegv and deadlocks... > > > > I moved the static variables to global scope and the problem > > disappeared. Is it the correct fix of the problem? Should I submit a > > patch? > > > > Comments? Ideas? > > John > > _______________________________________________ > > osg-users mailing list > > [email protected] > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or > > g > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

