diff --git a/source/Event/Basic.cpp b/source/Event/Basic.cpp index e64f31d5..043efc54 100644 --- a/source/Event/Basic.cpp +++ b/source/Event/Basic.cpp @@ -33,17 +33,19 @@ BasicEvent::BasicEvent(SQInt32 type, bool suspended) noexcept , m_Data() , m_Suspended(suspended) { + // Attach to the specified event signal Attach(); + // Receive notification when the VM is about to be closed to release object references + _Core->VMClose.Connect< BasicEvent, &BasicEvent::VMClose >(this); } // ------------------------------------------------------------------------------------------------ BasicEvent::~BasicEvent() { + // Detach from the specified event signal Detach(); - // Release the reference to the specified callback - m_OnTrigger.Release2(); - // Release the reference to the specified user data - m_Data.Release(); + // Stop receiving notification when the VM is about to be closed + _Core->VMClose.Disconnect< BasicEvent, &BasicEvent::VMClose >(this); } // ------------------------------------------------------------------------------------------------ @@ -82,10 +84,30 @@ bool BasicEvent::operator >= (const BasicEvent & o) const noexcept return (m_Type >= o.m_Type); } +// ------------------------------------------------------------------------------------------------ +void BasicEvent::VMClose() noexcept +{ + // Release the reference to the specified callbacks + m_OnTrigger.Release2(); + // Release the reference to the specified user data + m_Data.Release(); +} + // ------------------------------------------------------------------------------------------------ SQInt32 BasicEvent::Cmp(const BasicEvent & o) const noexcept { - return m_Type == o.m_Type ? 0 : (m_Type > o.m_Type ? 1 : -1); + if (m_Type == o.m_Type) + { + return 0; + } + else if (m_Type > o.m_Type) + { + return 1; + } + else + { + return -1; + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Event/Basic.hpp b/source/Event/Basic.hpp index 052bf7ca..f4bda827 100644 --- a/source/Event/Basic.hpp +++ b/source/Event/Basic.hpp @@ -117,6 +117,11 @@ public: return (m_Type == EVT_UNKNOWN || m_Type >= EVT_COUNT); } + /* -------------------------------------------------------------------------------------------- + * ... + */ + void VMClose() noexcept; + /* -------------------------------------------------------------------------------------------- * ... */ diff --git a/source/Event/Global.cpp b/source/Event/Global.cpp index cb076208..6c74c75f 100644 --- a/source/Event/Global.cpp +++ b/source/Event/Global.cpp @@ -50,6 +50,8 @@ GlobalEvent::GlobalEvent(SQInt32 type, bool suspended) noexcept { // Attach to the specified event signal Attach(); + // Receive notification when the VM is about to be closed to release object references + _Core->VMClose.Connect< GlobalEvent, &GlobalEvent::VMClose >(this); /* Entity filters are empty so there's nothing to hook to! */ } @@ -58,16 +60,9 @@ GlobalEvent::~GlobalEvent() { // Detach from the specified event signal Detach(); + // Stop receiving notification when the VM is about to be closed + _Core->VMClose.Disconnect< GlobalEvent, &GlobalEvent::VMClose >(this); /* We're expecting the entity filters to unhook themselves from the destroy signal! */ - - // Release the reference to the specified callbacks - m_OnTrigger.Release2(); - m_OnInclude.Release2(); - m_OnExclude.Release2(); - m_OnCleared.Release2(); - m_OnRelease.Release2(); - // Release the reference to the specified user data - m_Data.Release(); } // ------------------------------------------------------------------------------------------------ @@ -106,6 +101,19 @@ bool GlobalEvent::operator >= (const GlobalEvent & o) const noexcept return (m_Type >= o.m_Type); } +// ------------------------------------------------------------------------------------------------ +void GlobalEvent::VMClose() noexcept +{ + // Release the reference to the specified callbacks + m_OnTrigger.Release2(); + m_OnInclude.Release2(); + m_OnExclude.Release2(); + m_OnCleared.Release2(); + m_OnRelease.Release2(); + // Release the reference to the specified user data + m_Data.Release(); +} + // ------------------------------------------------------------------------------------------------ SQInt32 GlobalEvent::Cmp(const GlobalEvent & o) const noexcept { diff --git a/source/Event/Global.hpp b/source/Event/Global.hpp index 593bd404..3fb3f023 100644 --- a/source/Event/Global.hpp +++ b/source/Event/Global.hpp @@ -365,6 +365,11 @@ public: return (m_Type == EVT_UNKNOWN || m_Type >= EVT_COUNT); } + /* -------------------------------------------------------------------------------------------- + * ... + */ + void VMClose() noexcept; + /* -------------------------------------------------------------------------------------------- * ... */ diff --git a/source/Event/Local.cpp b/source/Event/Local.cpp index eeb1154b..bf4b84c2 100644 --- a/source/Event/Local.cpp +++ b/source/Event/Local.cpp @@ -48,6 +48,8 @@ LocalEvent::LocalEvent(SQInt32 type, bool suspended) noexcept , m_Textdraws(this) , m_Vehicles(this) { + // Receive notification when the VM is about to be closed to release object references + _Core->VMClose.Connect< LocalEvent, &LocalEvent::VMClose >(this); /* Entity filters are empty so there's nothing to hook right now! */ } @@ -56,16 +58,9 @@ LocalEvent::~LocalEvent() { // Detach from all attached signals Detach(); + // Stop receiving notification when the VM is about to be closed + _Core->VMClose.Disconnect< LocalEvent, &LocalEvent::VMClose >(this); /* The entity filters should to unhook themselves from the destroy signal! */ - - // Release the reference to the specified callbacks - m_OnTrigger.Release2(); - m_OnInclude.Release2(); - m_OnExclude.Release2(); - m_OnCleared.Release2(); - m_OnRelease.Release2(); - // Release the reference to the specified user data - m_Data.Release(); } // ------------------------------------------------------------------------------------------------ @@ -104,6 +99,19 @@ bool LocalEvent::operator >= (const LocalEvent & o) const noexcept return (m_Type >= o.m_Type); } +// ------------------------------------------------------------------------------------------------ +void LocalEvent::VMClose() noexcept +{ + // Release the reference to the specified callbacks + m_OnTrigger.Release2(); + m_OnInclude.Release2(); + m_OnExclude.Release2(); + m_OnCleared.Release2(); + m_OnRelease.Release2(); + // Release the reference to the specified user data + m_Data.Release(); +} + // ------------------------------------------------------------------------------------------------ SQInt32 LocalEvent::Cmp(const LocalEvent & o) const noexcept { diff --git a/source/Event/Local.hpp b/source/Event/Local.hpp index b888358f..022c5c7b 100644 --- a/source/Event/Local.hpp +++ b/source/Event/Local.hpp @@ -365,6 +365,11 @@ public: return (m_Type == EVT_UNKNOWN || m_Type >= EVT_COUNT); } + /* -------------------------------------------------------------------------------------------- + * ... + */ + void VMClose() noexcept; + /* -------------------------------------------------------------------------------------------- * ... */