From 9fa684126636e302b2cc96b1efae7137c6a4940b Mon Sep 17 00:00:00 2001 From: Pariring Date: Thu, 10 Nov 2022 18:10:35 +0900 Subject: [PATCH] fix: crash on windows --- Runtime/SkyHookManager.cs | 16 +++++++++++++--- Runtime/SkyHookNative.cs | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Runtime/SkyHookManager.cs b/Runtime/SkyHookManager.cs index 7e03eb3..9368538 100644 --- a/Runtime/SkyHookManager.cs +++ b/Runtime/SkyHookManager.cs @@ -40,6 +40,8 @@ namespace SkyHook // ReSharper disable once MemberCanBePrivate.Global public static readonly UnityEvent KeyUpdated = new(); + private SkyHookNative.Callback _callback; + /// /// The instance of . /// A new instance will be created if it does not exist. @@ -85,24 +87,32 @@ namespace SkyHook { try { - var result = SkyHookNative.StartHook(HookCallback); + _callback = HookCallback; + var result = SkyHookNative.StartHook(_callback); + if (result != null) { exception = new SkyHookException(result); } - + isHookActive = true; started = true; - + _mre.WaitOne(); + + Debug.Log("Thread ended"); } catch (Exception e) { exception = e; + Debug.LogError(e); throw; } }).Start(); + + isHookActive = true; + started = true; while (!started && exception == null) { diff --git a/Runtime/SkyHookNative.cs b/Runtime/SkyHookNative.cs index 59b3a87..4032032 100644 --- a/Runtime/SkyHookNative.cs +++ b/Runtime/SkyHookNative.cs @@ -10,6 +10,7 @@ namespace SkyHook /// /// The native callback handled by . /// + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void Callback(SkyHookEvent ev); private const string Lib = "skyhook";