(svn r8937) [cpp_gui] -Fix(r8931): the global map of Window Factories needs to be constructed on the fly. Otherwise it is not sure that it will be constructed before first WindowFactory. (Bjarni) cpp_gui
authorKUDr
Tue, 27 Feb 2007 23:54:28 +0000
branchcpp_gui
changeset 6267 7c8ec33959b1
parent 6266 3fa43db5af91
child 6268 4b5241e5dd10
(svn r8937) [cpp_gui] -Fix(r8931): the global map of Window Factories needs to be constructed on the fly. Otherwise it is not sure that it will be constructed before first WindowFactory. (Bjarni)
src/window.cpp
src/window.h
--- a/src/window.cpp	Tue Feb 27 23:42:47 2007 +0000
+++ b/src/window.cpp	Tue Feb 27 23:54:28 2007 +0000
@@ -17,8 +17,6 @@
 #include "helpers.hpp"
 #include "widget/window_events.hpp"
 
-/*static*/ WindowFactory::Factories WindowFactory::s_factories;
-
 // delta between mouse cursor and upper left corner of dragged window
 static Point _drag_delta;
 
--- a/src/window.h	Tue Feb 27 23:42:47 2007 +0000
+++ b/src/window.h	Tue Feb 27 23:54:28 2007 +0000
@@ -1032,7 +1032,11 @@
 
 	typedef std::map<WindowClass, WindowFactory*> Factories;
 
-	static Factories s_factories;
+	static Factories& GetFactories()
+	{
+		static Factories s_factories;
+		return s_factories;
+	}
 
 	WindowClass m_cls;
 	CreateFn    m_creator;
@@ -1041,19 +1045,19 @@
 		: m_cls(cls)
 		, m_creator(creator)
 	{
-		std::pair<Factories::iterator, bool> P = s_factories.insert(Factories::value_type(m_cls, this));
+		std::pair<Factories::iterator, bool> P = GetFactories().insert(Factories::value_type(m_cls, this));
 		assert(P.second);
 	}
 
 	~WindowFactory()
 	{
-		s_factories.erase(m_cls);
+		GetFactories().erase(m_cls);
 	}
 
 	static BaseWindow* NewWindow(WindowClass cls, WindowNumber num)
 	{
-		Factories::iterator it = s_factories.find(cls);
-		if (it == s_factories.end()) return NULL;
+		Factories::iterator it = GetFactories().find(cls);
+		if (it == GetFactories().end()) return NULL;
 		WindowFactory *f = (*it).second;
 		BaseWindow *w = f->m_creator(num);
 		return w;