From 83b84eb2f478e20fc59c4e00ea4ac461dc5fc38b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 6 Jun 2009 10:08:43 +0000 Subject: [PATCH] Introduced depend_on template and usage in RenderBin.cpp's singleton to solve crash on exit in static builds. --- include/osg/Referenced | 7 +++++++ src/osgUtil/RenderBin.cpp | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/osg/Referenced b/include/osg/Referenced index f851f3dbf..725746703 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -31,6 +31,13 @@ namespace osg { class DeleteHandler; class Observer; +/** template class to help enforce static initialization order. */ +template +struct depends_on +{ + depends_on() { M(); } +}; + /** Base class from providing referencing counted objects.*/ class OSG_EXPORT Referenced { diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index b33cafb19..99340fd06 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -26,8 +26,8 @@ using namespace osg; using namespace osgUtil; - -class RenderBinPrototypeList : public osg::Referenced, public std::map< std::string, osg::ref_ptr > +class RenderBinPrototypeList : osg::depends_on, + public osg::Referenced, public std::map< std::string, osg::ref_ptr > { public: RenderBinPrototypeList() {} @@ -83,8 +83,17 @@ void RenderBin::removeRenderBinPrototype(RenderBin* proto) RenderBinPrototypeList* list = renderBinPrototypeList(); if (list && proto) { - RenderBinPrototypeList::iterator itr = list->find(proto->className()); - if (itr != list->end()) list->erase(itr); + for(RenderBinPrototypeList::iterator itr = list->begin(); + itr != list->end(); + ++itr) + { + if (itr->second == proto) + { + // osg::notify(osg::NOTICE)<<"Found protype, now erasing "<first<erase(itr); + return; + } + } } }