Commit f39ea5a
authored
Fix "Handle is not initialized" for Unity 2021.2.x games (#232)
When the mono object is a System.Action object it seems GetGcHandlePtrFromIl2CppObject(pointer) returns a null pointer for the Garbage Collector Handle (or well IntPtr.Zero). This causes GCHandle.FromIntPtr(gcHandle) to throw an excepction.
One solution after a lot of back and forth was to essentially check if the object class is a Delegate type class (which includes System.Action) and if so, get the garbage collector handle on the mTarget of the delegate object. This way in my testing the code will not interfere with other Unity versions - yet it allows to hook onto my test game - which happens to be a 2021.2.x game compiled with IL2CPP.
In other Unity versions if (gcHandle == IntPtr.Zero) should be false so I doubt this would interfere in any way (it worked fine in other tested games for me).
----
It's a hack but it seems to be working well, merging for v1.5.1. This code will be replaced in v2.0 with a proper fix.1 parent 400ad63 commit f39ea5a
1 file changed
+21
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
19 | 40 | | |
20 | 41 | | |
21 | 42 | | |
| |||
0 commit comments