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