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 ca9b041f54
commit 1181deb5df
6 changed files with 44 additions and 0 deletions

View File

@@ -336,7 +336,46 @@ void MCore::ReloadScriptingAssemblyLoadContext()
{
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
for (auto e : CachedClassHandles)
{
e.Value->_hasCachedAttributes = false;
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"));
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);