From f5a3c409340c890af011fc0ff9eb8aaaafba2e82 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Sep 2012 13:48:23 +0000 Subject: [PATCH] Moved the OSG_INIT_SINGLETON_PROXY macro into include/osg/Object to make it more generally useful and added it's usage into the RenderBinPrototypeList initialization. --- include/osg/Object | 3 +++ src/osgUtil/RenderBin.cpp | 4 ++++ src/osgViewer/Scene.cpp | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/osg/Object b/include/osg/Object index 4a0e8d8fc..7a4e7063f 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -42,6 +42,9 @@ class UserDataContainer; virtual const char* libraryName() const { return #library; }\ virtual const char* className() const { return #name; } +/** Helper macro that creates a static proxy object to call singleton function on it's construction, ensuring that the singleton gets initialized at startup.*/ +#define OSG_INIT_SINGLETON_PROXY(ProxyName, Func) static struct ProxyName{ ProxyName() { Func; } } s_##ProxyName; + /** Base class/standard interface for objects which require IO support, cloning and reference counting. Based on GOF Composite, Prototype and Template Method patterns. diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index ca442949b..cb398eb16 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -54,6 +54,10 @@ static RenderBinPrototypeList* renderBinPrototypeList() return s_renderBinPrototypeList.get(); } +// Use a proxy to force the initialization of the the SceneSingleton during static initialization +OSG_INIT_SINGLETON_PROXY(RenderBinSingletonProxy, renderBinPrototypeList()) + + RenderBin* RenderBin::getRenderBinPrototype(const std::string& binName) { RenderBinPrototypeList* list = renderBinPrototypeList(); diff --git a/src/osgViewer/Scene.cpp b/src/osgViewer/Scene.cpp index 2d04f6c6a..d9af8002d 100644 --- a/src/osgViewer/Scene.cpp +++ b/src/osgViewer/Scene.cpp @@ -16,7 +16,6 @@ using namespace osgViewer; -#define OSG_INIT_SINGLETON_PROXY(ProxyName, Func) static struct ProxyName{ ProxyName() { Func; } } s_##ProxyName; namespace osgViewer {