Fix ManagedDictionary cache to be cleared on hot-reload
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
#include "ManagedDictionary.h"
|
#include "ManagedDictionary.h"
|
||||||
|
|
||||||
#if USE_CSHARP
|
#if USE_CSHARP
|
||||||
Dictionary<ManagedDictionary::KeyValueType, MTypeObject*> ManagedDictionary::CachedDictionaryTypes;
|
Dictionary<ManagedDictionary::KeyValueType, MTypeObject*> ManagedDictionary::CachedTypes;
|
||||||
#if !USE_MONO_AOT
|
#if !USE_MONO_AOT
|
||||||
ManagedDictionary::MakeGenericTypeThunk ManagedDictionary::MakeGenericType;
|
ManagedDictionary::MakeGenericTypeThunk ManagedDictionary::MakeGenericType;
|
||||||
ManagedDictionary::CreateInstanceThunk ManagedDictionary::CreateInstance;
|
ManagedDictionary::CreateInstanceThunk ManagedDictionary::CreateInstance;
|
||||||
|
|||||||
@@ -22,17 +22,18 @@ struct FLAXENGINE_API ManagedDictionary
|
|||||||
public:
|
public:
|
||||||
struct KeyValueType
|
struct KeyValueType
|
||||||
{
|
{
|
||||||
MType* keyType;
|
MType* KeyType;
|
||||||
MType* valueType;
|
MType* ValueType;
|
||||||
|
|
||||||
bool operator==(const KeyValueType& other) const
|
bool operator==(const KeyValueType& other) const
|
||||||
{
|
{
|
||||||
return keyType == other.keyType && valueType == other.valueType;
|
return KeyType == other.KeyType && ValueType == other.ValueType;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Dictionary<KeyValueType, MTypeObject*> CachedDictionaryTypes;
|
friend class Scripting;
|
||||||
|
static Dictionary<KeyValueType, MTypeObject*> CachedTypes;
|
||||||
|
|
||||||
#if !USE_MONO_AOT
|
#if !USE_MONO_AOT
|
||||||
typedef MTypeObject* (*MakeGenericTypeThunk)(MObject* instance, MTypeObject* genericType, MArray* genericArgs, MObject** exception);
|
typedef MTypeObject* (*MakeGenericTypeThunk)(MObject* instance, MTypeObject* genericType, MArray* genericArgs, MObject** exception);
|
||||||
@@ -158,7 +159,7 @@ public:
|
|||||||
// Check if the generic type was generated earlier
|
// Check if the generic type was generated earlier
|
||||||
KeyValueType cacheKey = { keyType, valueType };
|
KeyValueType cacheKey = { keyType, valueType };
|
||||||
MTypeObject* dictionaryType;
|
MTypeObject* dictionaryType;
|
||||||
if (CachedDictionaryTypes.TryGet(cacheKey, dictionaryType))
|
if (CachedTypes.TryGet(cacheKey, dictionaryType))
|
||||||
return dictionaryType;
|
return dictionaryType;
|
||||||
|
|
||||||
MTypeObject* genericType = MUtils::GetType(StdTypesContainer::Instance()->DictionaryClass);
|
MTypeObject* genericType = MUtils::GetType(StdTypesContainer::Instance()->DictionaryClass);
|
||||||
@@ -186,7 +187,7 @@ public:
|
|||||||
ex.Log(LogType::Error, TEXT(""));
|
ex.Log(LogType::Error, TEXT(""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
CachedDictionaryTypes.Add(cacheKey, dictionaryType);
|
CachedTypes.Add(cacheKey, dictionaryType);
|
||||||
return dictionaryType;
|
return dictionaryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,8 +265,8 @@ public:
|
|||||||
|
|
||||||
inline uint32 GetHash(const ManagedDictionary::KeyValueType& other)
|
inline uint32 GetHash(const ManagedDictionary::KeyValueType& other)
|
||||||
{
|
{
|
||||||
uint32 hash = ::GetHash((void*)other.keyType);
|
uint32 hash = ::GetHash((void*)other.KeyType);
|
||||||
CombineHash(hash, ::GetHash((void*)other.valueType));
|
CombineHash(hash, ::GetHash((void*)other.ValueType));
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "ManagedCLR/MCore.h"
|
#include "ManagedCLR/MCore.h"
|
||||||
#include "ManagedCLR/MException.h"
|
#include "ManagedCLR/MException.h"
|
||||||
#include "Internal/StdTypesContainer.h"
|
#include "Internal/StdTypesContainer.h"
|
||||||
|
#include "Internal/ManagedDictionary.h"
|
||||||
#include "Engine/Core/LogContext.h"
|
#include "Engine/Core/LogContext.h"
|
||||||
#include "Engine/Core/ObjectsRemovalService.h"
|
#include "Engine/Core/ObjectsRemovalService.h"
|
||||||
#include "Engine/Core/Types/TimeSpan.h"
|
#include "Engine/Core/Types/TimeSpan.h"
|
||||||
@@ -720,6 +721,7 @@ void Scripting::Reload(bool canTriggerSceneReload)
|
|||||||
modules.Clear();
|
modules.Clear();
|
||||||
_nonNativeModules.ClearDelete();
|
_nonNativeModules.ClearDelete();
|
||||||
_hasGameModulesLoaded = false;
|
_hasGameModulesLoaded = false;
|
||||||
|
ManagedDictionary::CachedTypes.Clear();
|
||||||
|
|
||||||
// Release and create a new assembly load context for user assemblies
|
// Release and create a new assembly load context for user assemblies
|
||||||
MCore::UnloadScriptingAssemblyLoadContext();
|
MCore::UnloadScriptingAssemblyLoadContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user