From 1d7ba2210afd566d16303966a2e52c75877cef17 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 1 Sep 2022 22:55:29 +0200 Subject: [PATCH] Fix crash on API event in C# after Editor hot-reload --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 9d0e22401..dc5190f36 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -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();