diff --git a/src/common/any.cpp b/src/common/any.cpp index 76f32a9824..b4141c47e5 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -121,16 +121,27 @@ private: wxVector m_anyToVariantRegs; }; -static wxScopedPtr g_wxAnyValueTypeGlobals; +static wxScopedPtr& GetAnyValueTypeGlobals() +{ + static wxScopedPtr s_wxAnyValueTypeGlobals; + if ( !s_wxAnyValueTypeGlobals ) + { + // Notice that it is _not_ sufficient to just initialize the static + // object like this because it can be used after it was reset by + // wxAnyValueTypeGlobalsManager if the library is shut down and then + // initialized again. + s_wxAnyValueTypeGlobals.reset(new wxAnyValueTypeGlobals()); + } + + return s_wxAnyValueTypeGlobals; +} WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData) void wxPreRegisterAnyToVariant(wxAnyToVariantRegistration* reg) { - if ( !g_wxAnyValueTypeGlobals ) - g_wxAnyValueTypeGlobals.reset(new wxAnyValueTypeGlobals()); - g_wxAnyValueTypeGlobals->PreRegisterAnyToVariant(reg); + GetAnyValueTypeGlobals()->PreRegisterAnyToVariant(reg); } bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) @@ -175,7 +186,7 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) // Find matching factory function wxVariantDataFactory f = - g_wxAnyValueTypeGlobals->FindVariantDataFactory(any.GetType()); + GetAnyValueTypeGlobals()->FindVariantDataFactory(any.GetType()); wxVariantData* data = NULL; @@ -223,7 +234,7 @@ public: } virtual void OnExit() wxOVERRIDE { - g_wxAnyValueTypeGlobals.reset(); + GetAnyValueTypeGlobals().reset(); } private: };