diff --git a/SHADE_Managed/src/Components/UIElement.cxx b/SHADE_Managed/src/Components/UIElement.cxx index cc854bd2..8e6134e1 100644 --- a/SHADE_Managed/src/Components/UIElement.cxx +++ b/SHADE_Managed/src/Components/UIElement.cxx @@ -28,6 +28,18 @@ namespace SHADE : Component(entity) {} + void UIElement::ClearStaticEventData() + { + if (onClickEventMap != nullptr) + onClickEventMap->Clear(); + if (onReleasedEventMap != nullptr) + onReleasedEventMap->Clear(); + if (onHoverEnterEventMap != nullptr) + onHoverEnterEventMap->Clear(); + if (onHoverExitEventMap != nullptr) + onHoverExitEventMap->Clear(); + } + /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ @@ -37,7 +49,7 @@ namespace SHADE if (onClickEventMap == nullptr) { onClickEventMap = gcnew System::Collections::Generic::Dictionary(); - } + } // Create event if it wasn't before if (!onClickEventMap->ContainsKey(owner.EntityId)) diff --git a/SHADE_Managed/src/Components/UIElement.hxx b/SHADE_Managed/src/Components/UIElement.hxx index 7b762ce3..c93e1e55 100644 --- a/SHADE_Managed/src/Components/UIElement.hxx +++ b/SHADE_Managed/src/Components/UIElement.hxx @@ -73,6 +73,15 @@ namespace SHADE CallbackEvent^ get(); } + internal: + /*-----------------------------------------------------------------------------*/ + /* Static Clear Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Disposes static event data which may contains data from SHADE_Scripting. + /// + static void ClearStaticEventData(); + private: /*-----------------------------------------------------------------------------*/ /* Event Handling Functions */ @@ -108,6 +117,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Static Data Members */ /*-----------------------------------------------------------------------------*/ + // As these hold references to code in SHADE_Scripting, we must remember to dispose of them when changing scenes static System::Collections::Generic::Dictionary^ onClickEventMap; static System::Collections::Generic::Dictionary^ onReleasedEventMap; static System::Collections::Generic::Dictionary^ onHoverEnterEventMap; diff --git a/SHADE_Managed/src/Engine/ECS.hxx b/SHADE_Managed/src/Engine/ECS.hxx index 18acf30d..64207f72 100644 --- a/SHADE_Managed/src/Engine/ECS.hxx +++ b/SHADE_Managed/src/Engine/ECS.hxx @@ -51,7 +51,7 @@ namespace SHADE /// specified Component. /// generic where T : BaseComponent - static T GetComponent(EntityID entity); + static T GetComponent(EntityID entity); /// /// Retrieves the first Component from the specified GameObject's children that /// matches the specified type. diff --git a/SHADE_Managed/src/Engine/EngineInterface.cxx b/SHADE_Managed/src/Engine/EngineInterface.cxx index 2009b2e5..50f8fbc2 100644 --- a/SHADE_Managed/src/Engine/EngineInterface.cxx +++ b/SHADE_Managed/src/Engine/EngineInterface.cxx @@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" #include "Scripts/ScriptStore.hxx" +#include "Components/UIElement.hxx" namespace SHADE { @@ -43,6 +44,9 @@ namespace SHADE oss << "[EngineInterface] Unloading " << Convert::ToNative(ManagedLibraryName) << ".dll"; ScriptStore::Exit(); + // Unload static data of components that have access to the assembly + UIElement::ClearStaticEventData(); + // Unload the script scriptContext->Unload(); scriptContext = nullptr;