Skip to content

Commit 8c73932

Browse files
committed
Fix crash when exception is thrown
1 parent bd4bf38 commit 8c73932

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/DllManipulator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public partial class DllManipulator
2222
public static DllManipulatorOptions Options { get; set; }
2323
private static int _unityMainThreadId;
2424
private static string _assetsPath;
25+
private static LinkedList<object> _antiGcRefHolder = new LinkedList<object>();
2526
private static readonly ReaderWriterLockSlim _nativeFunctionLoadLock = new ReaderWriterLockSlim();
2627
private static ModuleBuilder _customDelegateTypesModule = null;
2728
private static readonly Dictionary<string, NativeDll> _dlls = new Dictionary<string, NativeDll>();
@@ -222,6 +223,9 @@ private static DynamicMethod GetNativeFunctionMockMethod(MethodInfo nativeMethod
222223
}
223224

224225
GenerateNativeFunctionMockBody(mockedDynamicMethod.GetILGenerator(), parameters, targetDelegateInvokeMethod, nativeFunctionIndex);
226+
227+
_antiGcRefHolder.AddLast(nativeFunction);
228+
_antiGcRefHolder.AddLast(mockedDynamicMethod);
225229
}
226230

227231
return mockedDynamicMethod;

0 commit comments

Comments
 (0)