fix: crash on windows

develop
paring 2022-11-10 18:10:35 +09:00
parent 5caebf2b34
commit 9fa6841266
Signed by: pikokr
GPG Key ID: 2C097B03E9D823C4
2 changed files with 14 additions and 3 deletions

View File

@ -40,6 +40,8 @@ namespace SkyHook
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
public static readonly UnityEvent<SkyHookEvent> KeyUpdated = new(); public static readonly UnityEvent<SkyHookEvent> KeyUpdated = new();
private SkyHookNative.Callback _callback;
/// <summary> /// <summary>
/// The instance of <see cref="SkyHookManager"/>. /// The instance of <see cref="SkyHookManager"/>.
/// A new instance will be created if it does not exist. /// A new instance will be created if it does not exist.
@ -85,24 +87,32 @@ namespace SkyHook
{ {
try try
{ {
var result = SkyHookNative.StartHook(HookCallback); _callback = HookCallback;
var result = SkyHookNative.StartHook(_callback);
if (result != null) if (result != null)
{ {
exception = new SkyHookException(result); exception = new SkyHookException(result);
} }
isHookActive = true; isHookActive = true;
started = true; started = true;
_mre.WaitOne(); _mre.WaitOne();
Debug.Log("Thread ended");
} }
catch (Exception e) catch (Exception e)
{ {
exception = e; exception = e;
Debug.LogError(e);
throw; throw;
} }
}).Start(); }).Start();
isHookActive = true;
started = true;
while (!started && exception == null) while (!started && exception == null)
{ {

View File

@ -10,6 +10,7 @@ namespace SkyHook
/// <summary> /// <summary>
/// The native callback handled by <see cref="SkyHookManager"/>. /// The native callback handled by <see cref="SkyHookManager"/>.
/// </summary> /// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Callback(SkyHookEvent ev); public delegate void Callback(SkyHookEvent ev);
private const string Lib = "skyhook"; private const string Lib = "skyhook";