From f003a0d4de73e0e02be396b39f2ba40ee245295c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=90=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Sun, 5 Jan 2025 01:47:58 +0400 Subject: [PATCH 1/3] Fix NullPointerException when native class is not present --- Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs index bd70a8ad..54a18d9a 100644 --- a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs +++ b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs @@ -40,10 +40,14 @@ public static T Get(IntPtr ptr) var newObj = Il2CppObjectBase.InitializerStore.Initializer(ptr); unsafe { - var nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)Il2CppClassPointerStore.NativeClassPtr); - if (!nativeClassStruct.HasFinalize) + var il2CppClass = (Il2CppClass*)Il2CppClassPointerStore.NativeClassPtr; + if (il2CppClass != null) { - Il2CppSystem.GC.ReRegisterForFinalize(newObj as Object ?? new Object(ptr)); + var nativeClassStruct = UnityVersionHandler.Wrap(il2CppClass); + if (!nativeClassStruct.HasFinalize) + { + Il2CppSystem.GC.ReRegisterForFinalize(newObj as Object ?? new Object(ptr)); + } } } From 2d3b038c6a320987ef600c988f962598d0f07e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=90=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Sun, 5 Jan 2025 07:40:05 +0400 Subject: [PATCH 2/3] Reformat statement --- Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs index 54a18d9a..6c857cb8 100644 --- a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs +++ b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs @@ -40,14 +40,10 @@ public static T Get(IntPtr ptr) var newObj = Il2CppObjectBase.InitializerStore.Initializer(ptr); unsafe { - var il2CppClass = (Il2CppClass*)Il2CppClassPointerStore.NativeClassPtr; - if (il2CppClass != null) + var nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)Il2CppClassPointerStore.NativeClassPtr); + if (!nativeClassStruct?.HasFinalize is true) { - var nativeClassStruct = UnityVersionHandler.Wrap(il2CppClass); - if (!nativeClassStruct.HasFinalize) - { - Il2CppSystem.GC.ReRegisterForFinalize(newObj as Object ?? new Object(ptr)); - } + Il2CppSystem.GC.ReRegisterForFinalize(newObj as Object ?? new Object(ptr)); } } From baeb625503cd077d9307f35f71dcedbb5a1e5992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=90=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Mon, 13 Jan 2025 17:51:30 +0400 Subject: [PATCH 3/3] Reformat statement --- Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs index 6c857cb8..9a78e6ea 100644 --- a/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs +++ b/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs @@ -41,7 +41,7 @@ public static T Get(IntPtr ptr) unsafe { var nativeClassStruct = UnityVersionHandler.Wrap((Il2CppClass*)Il2CppClassPointerStore.NativeClassPtr); - if (!nativeClassStruct?.HasFinalize is true) + if (nativeClassStruct?.HasFinalize is false) { Il2CppSystem.GC.ReRegisterForFinalize(newObj as Object ?? new Object(ptr)); }