From 46ec55c138363c82239b58103bc722fc8bf1d97b Mon Sep 17 00:00:00 2001 From: MFransen69 <39826971+MFransen69@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:26:28 +0100 Subject: [PATCH] [Core] Singleton dispose Fixes (#1467) * [Core] Singleton dispose Fixes * Update MessageStore.cpp --------- Co-authored-by: Pierre Wielders --- Source/core/MessageStore.cpp | 9 +++++++-- Source/core/Singleton.h | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/core/MessageStore.cpp b/Source/core/MessageStore.cpp index c2299af790..e394e1e936 100644 --- a/Source/core/MessageStore.cpp +++ b/Source/core/MessageStore.cpp @@ -1,4 +1,4 @@ -/* +/* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * @@ -52,6 +52,7 @@ ENUM_CONVERSION_END(Core::Messaging::Metadata::type) _adminLock.Lock(); while (_controlList.size() > 0) { + TRACE_L1(_T("tracecontrol %s, size = %u was not disposed before"), typeid(*_controlList.front()).name(), _controlList.size()); _controlList.front()->Destroy(); } @@ -106,7 +107,11 @@ ENUM_CONVERSION_END(Core::Messaging::Metadata::type) Controls& ControlsInstance() { - return (Core::SingletonType::Instance()); + // do not use the SingleTonType as ControlsInstance will be referenced + // the SingleTonType dispose and the Controls would be newly created instead + // of the current one used + static Controls instance; + return instance; } static Core::Messaging::IStore* _storage; diff --git a/Source/core/Singleton.h b/Source/core/Singleton.h index 78cdf971d8..8735936c56 100644 --- a/Source/core/Singleton.h +++ b/Source/core/Singleton.h @@ -103,6 +103,7 @@ namespace Core { { ListInstance().Unregister(this); ASSERT(g_TypedSingleton != nullptr); + g_TypedSingleton = nullptr; } public: @@ -160,14 +161,18 @@ namespace Core { ASSERT(g_TypedSingleton != nullptr); } - inline static void Dispose() + inline static bool Dispose() { // Unprotected. Make sure the dispose is *ONLY* called // after all usage of the singlton is completed!!! + bool disposed = false; if (g_TypedSingleton != nullptr) { delete g_TypedSingleton; + // note destructor will set g_TypedSingleton to nullptr; + disposed = true; } + return disposed; } private: