Fix crash when using attributes cache after hot-reload in editor

This commit is contained in:
Wojtek Figat
2024-10-24 23:38:25 +02:00
parent 8338ec6076
commit 62ece0d92e
6 changed files with 44 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
/// </summary> /// </summary>
class FLAXENGINE_API MAssembly class FLAXENGINE_API MAssembly
{ {
friend MCore;
friend MDomain; friend MDomain;
friend Scripting; friend Scripting;

View File

@@ -10,6 +10,7 @@
class FLAXENGINE_API MEvent class FLAXENGINE_API MEvent
{ {
friend MClass; friend MClass;
friend MCore;
protected: protected:
#if USE_MONO #if USE_MONO

View File

@@ -11,6 +11,7 @@
class FLAXENGINE_API MField class FLAXENGINE_API MField
{ {
friend MClass; friend MClass;
friend MCore;
protected: protected:
#if USE_MONO #if USE_MONO

View File

@@ -16,6 +16,7 @@ class FLAXENGINE_API MMethod
friend MClass; friend MClass;
friend MProperty; friend MProperty;
friend MEvent; friend MEvent;
friend MCore;
protected: protected:
#if USE_MONO #if USE_MONO

View File

@@ -12,6 +12,7 @@
class FLAXENGINE_API MProperty class FLAXENGINE_API MProperty
{ {
friend MClass; friend MClass;
friend MCore;
protected: protected:
#if USE_MONO #if USE_MONO

View File

@@ -336,7 +336,46 @@ void MCore::ReloadScriptingAssemblyLoadContext()
{ {
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108) // Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
for (auto e : CachedClassHandles) for (auto e : CachedClassHandles)
{
e.Value->_hasCachedAttributes = false;
e.Value->_attributes.Clear(); e.Value->_attributes.Clear();
}
for (auto e : CachedAssemblyHandles)
{
MAssembly* a = e.Value;
if (!a->IsLoaded() || !a->_hasCachedClasses)
continue;
for (auto q : a->GetClasses())
{
MClass* c = q.Value;
c->_hasCachedAttributes = false;
c->_attributes.Clear();
if (c->_hasCachedMethods)
{
for (MMethod* m : c->GetMethods())
{
m->_hasCachedAttributes = false;
m->_attributes.Clear();
}
}
if (c->_hasCachedFields)
{
for (MField* f : c->GetFields())
{
f->_hasCachedAttributes = false;
f->_attributes.Clear();
}
}
if (c->_hasCachedProperties)
{
for (MProperty* p : c->GetProperties())
{
p->_hasCachedAttributes = false;
p->_attributes.Clear();
}
}
}
}
static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext")); static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr); CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);