Skip to content

Commit

Permalink
[Core] Singleton dispose Fixes (#1467)
Browse files Browse the repository at this point in the history
* [Core] Singleton dispose Fixes

* Update MessageStore.cpp

---------

Co-authored-by: Pierre Wielders <[email protected]>
  • Loading branch information
MFransen69 and pwielders authored Dec 12, 2023
1 parent 74eb787 commit e71f91f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Source/core/MessageStore.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -106,7 +107,11 @@ ENUM_CONVERSION_END(Core::Messaging::Metadata::type)

Controls& ControlsInstance()
{
return (Core::SingletonType<Controls>::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;
Expand Down
7 changes: 6 additions & 1 deletion Source/core/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Core {
{
ListInstance().Unregister(this);
ASSERT(g_TypedSingleton != nullptr);
g_TypedSingleton = nullptr;
}

public:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e71f91f

Please sign in to comment.