RequiDev/ReMod.Core

Null reference exception on add component

Closed this issue · 6 comments

https://github.com/RequiDev/ReMod.Core/blob/1d00b095a1ab8255fb58b1df53df216ea24d4b15/UI/ReMenuToggle.cs#L79-80

Adding a ToggleButton to a ReMenuCategory on the Launch Pad throws an error.

[00:26:42.612] [ERROR] Exception in coroutine of type TestMod.UserInterface+<PreStart>d__9, TestMod, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: System.TypeInitializationException: The type initializer for 'MethodInfoStoreGeneric_AddComponent_Public_T_0`1' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object

  at UnhollowerRuntimeLib.ClassInjector.ClassFromTypePatch (UnhollowerBaseLib.Runtime.Il2CppTypeStruct* type) [0x0000e] in <6f5eac61249445bd9451af212421fd1b>:0 

  at (wrapper managed-to-native) UnhollowerBaseLib.IL2CPP.il2cpp_runtime_invoke(intptr,intptr,void**,intptr&)

  at Il2CppSystem.Type.internal_from_handle (System.IntPtr handle) [0x00018] in <76673102690b4e66b10bd754f7289008>:0 

  at UnityEngine.GameObject+MethodInfoStoreGeneric_AddComponent_Public_T_0`1[T]..cctor () [0x00026] in <fe61195c83d847d5a838a33827daa06f>:0 

   --- End of inner exception stack trace ---

  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)

  at UnityEngine.GameObject.AddComponent[T] () [0x0000d] in <fe61195c83d847d5a838a33827daa06f>:0 

  at ReMod.Core.UI.ReMenuToggle..ctor (System.String text, System.String tooltip, System.Action`1[T] onToggle, UnityEngine.Transform parent, System.Boolean defaultValue) [0x00153] in <e4e3f0df54d749d8873c6e694498b706>:0 

  at ReMod.Core.UI.ReMenuCategory.AddToggle (System.String text, System.String tooltip, System.Action`1[T] onToggle, System.Boolean defaultValue) [0x0000e] in <e4e3f0df54d749d8873c6e694498b706>:0

I comment out the two lines, in question, and no longer get the errors.

Did you register the type in il2cpp space using unhollower?

Seems that I did not. Though shouldn't Core do that, on say, onAppStart? Or is it a bit of a niche thing, and probably should only be done if needed? (If my English even makes sense)

Yes. ReMod.Core should do that automatically you're correct. Don't forget this stuff is still WIP.

I'll think about a good way to do this.

Sounds good. Thanks.

Registered the scripts OnAppStart, things seem fine now. Thanks again.