Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidOperationException when using delegates #71

Open
PieKing1215 opened this issue Jan 23, 2023 · 0 comments
Open

InvalidOperationException when using delegates #71

PieKing1215 opened this issue Jan 23, 2023 · 0 comments

Comments

@PieKing1215
Copy link

I'm trying to add a listener to a delegate, but I get an exception when the event runs.

BepInEx 6.0.0-be.665
Game is Unity 2022.1, v29 metadata (BepInEx says Running under Unity 2021.2.0f1 though?)

Setup:

// GameEvent is `public delegate void GameEvent();` (class that extends `Il2CppSystem.MulticastDelegate`)
// Plugin.OnRoundBegin is `public static void OnRoundBegin() {}`

GameEvents.OnRoundBegin += (GameEvents.GameEvent)Plugin.OnRoundBegin;
// or
GameEvents.OnRoundBegin += (System.Action)Plugin.OnRoundBegin;

Error when the event happens:

[Error  :Il2CppInterop] Exception in IL2CPP-to-Managed trampoline, not passing it to il2cpp: System.InvalidOperationException: Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at Il2CppInterop.Runtime.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(IntPtr pointer) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Runtime/ClassInjectorBase.cs:line 15
   at (il2cpp delegate trampoline) System.Void_System.Action(IntPtr , Il2CppMethodInfo* )

I could just be doing something wrong, but I've tried a bunch of variations and couldn't get it to work.

(I wasn't 100% sure if I should open here or in BepInEx/BepInEx so feel free to transfer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant