Fixed issue where duplicate script assemblies are loaded again

This commit is contained in:
Kah Wei 2023-02-23 13:32:23 +08:00
parent d7846082a3
commit 7292f11cdb
4 changed files with 28 additions and 2 deletions

View File

@ -28,6 +28,18 @@ namespace SHADE
: Component(entity) : 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 */ /* Properties */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -73,6 +73,15 @@ namespace SHADE
CallbackEvent^ get(); CallbackEvent^ get();
} }
internal:
/*-----------------------------------------------------------------------------*/
/* Static Clear Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Disposes static event data which may contains data from SHADE_Scripting.
/// </summary>
static void ClearStaticEventData();
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Event Handling Functions */ /* Event Handling Functions */
@ -108,6 +117,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Static Data Members */ /* 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<Entity, CallbackEvent^>^ onClickEventMap; static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onClickEventMap;
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onReleasedEventMap; static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onReleasedEventMap;
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onHoverEnterEventMap; static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onHoverEnterEventMap;

View File

@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Utility/Convert.hxx" #include "Utility/Convert.hxx"
#include "Utility/Debug.hxx" #include "Utility/Debug.hxx"
#include "Scripts/ScriptStore.hxx" #include "Scripts/ScriptStore.hxx"
#include "Components/UIElement.hxx"
namespace SHADE namespace SHADE
{ {
@ -43,6 +44,9 @@ namespace SHADE
oss << "[EngineInterface] Unloading " << Convert::ToNative(ManagedLibraryName) << ".dll"; oss << "[EngineInterface] Unloading " << Convert::ToNative(ManagedLibraryName) << ".dll";
ScriptStore::Exit(); ScriptStore::Exit();
// Unload static data of components that have access to the assembly
UIElement::ClearStaticEventData();
// Unload the script // Unload the script
scriptContext->Unload(); scriptContext->Unload();
scriptContext = nullptr; scriptContext = nullptr;