Fix crash on API event in C# after Editor hot-reload

This commit is contained in:
Wojtek Figat
2022-09-01 22:55:29 +02:00
parent 8885412350
commit 1d7ba2210a

View File

@@ -1569,7 +1569,10 @@ namespace Flax.Build.Bindings
}
contents.Append(')').AppendLine();
contents.Append(" {").AppendLine();
contents.Append(" static MMethod* mmethod = nullptr;").AppendLine();
if (buildData.Target.IsEditor)
contents.Append(" MMethod* mmethod = nullptr;").AppendLine(); // TODO: find a better way to cache event method in editor and handle C# hot-reload
else
contents.Append(" static MMethod* mmethod = nullptr;").AppendLine();
contents.Append(" if (!mmethod)").AppendLine();
contents.AppendFormat(" mmethod = {1}::TypeInitializer.GetType().ManagedClass->GetMethod(\"Internal_{0}_Invoke\", {2});", eventInfo.Name, classTypeNameNative, paramsCount).AppendLine();
contents.Append(" CHECK(mmethod);").AppendLine();