Fix crash after scripting hot-reload in editor due to cached class attribute objects
#1108
This commit is contained in:
@@ -45,6 +45,11 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
static void UnloadEngine();
|
static void UnloadEngine();
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
// Called by Scripting in a middle of hot-reload (after unloading modules but before loading them again).
|
||||||
|
static void OnMidHotReload();
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utilities for C# object management.
|
/// Utilities for C# object management.
|
||||||
|
|||||||
@@ -299,6 +299,17 @@ void MCore::UnloadEngine()
|
|||||||
ShutdownHostfxr();
|
ShutdownHostfxr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
void MCore::OnMidHotReload()
|
||||||
|
{
|
||||||
|
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
|
||||||
|
for (auto e : CachedClassHandles)
|
||||||
|
e.Value->_attributes.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
||||||
{
|
{
|
||||||
static void* BoxValuePtr = GetStaticMethodPointer(TEXT("BoxValue"));
|
static void* BoxValuePtr = GetStaticMethodPointer(TEXT("BoxValue"));
|
||||||
|
|||||||
@@ -714,6 +714,14 @@ void MCore::UnloadEngine()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
void MCore::OnMidHotReload()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
||||||
{
|
{
|
||||||
return mono_value_box(mono_domain_get(), klass->GetNative(), value);
|
return mono_value_box(mono_domain_get(), klass->GetNative(), value);
|
||||||
|
|||||||
@@ -59,6 +59,14 @@ void MCore::UnloadEngine()
|
|||||||
MRootDomain = nullptr;
|
MRootDomain = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
void MCore::OnMidHotReload()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -665,6 +665,7 @@ void Scripting::Reload(bool canTriggerSceneReload)
|
|||||||
modules.Clear();
|
modules.Clear();
|
||||||
_nonNativeModules.ClearDelete();
|
_nonNativeModules.ClearDelete();
|
||||||
_hasGameModulesLoaded = false;
|
_hasGameModulesLoaded = false;
|
||||||
|
MCore::OnMidHotReload();
|
||||||
|
|
||||||
// Give GC a try to cleanup old user objects and the other mess
|
// Give GC a try to cleanup old user objects and the other mess
|
||||||
MCore::GC::Collect();
|
MCore::GC::Collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user