From 3b94deacbffe6a10ca403d52de6c2ada3e411e73 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 22 Feb 2024 15:58:56 +0900 Subject: [PATCH] fix: crash when process not found --- BorderlessGaming/Logic/Windows/Native.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/BorderlessGaming/Logic/Windows/Native.cs b/BorderlessGaming/Logic/Windows/Native.cs index 1bce2be..cf9d256 100644 --- a/BorderlessGaming/Logic/Windows/Native.cs +++ b/BorderlessGaming/Logic/Windows/Native.cs @@ -10,6 +10,7 @@ using BorderlessGaming.Logic.Models; using BorderlessGaming.Logic.Misc.Utilities; using BorderlessGaming.Logic.Windows.Audio; +using BorderlessGaming.Logic.Extensions; namespace BorderlessGaming.Logic.Windows { @@ -340,7 +341,7 @@ private static bool GetMainWindowForProcess_EnumWindows(IntPtr hWndEnumerated, u { if (IsWindowVisible(hWndEnumerated)) { - if ((uint) styleCurrentWindow_standard != 0) + if ((uint)styleCurrentWindow_standard != 0) { GetMainWindowForProcess_Value = hWndEnumerated; return false; @@ -440,7 +441,12 @@ bool Del(IntPtr hwnd, uint lParam) } uint processId; GetWindowThreadProcessId(ptr, out processId); - callback(new ProcessDetails(Process.GetProcessById((int)processId), ptr) + var process = ProcessExtensions.GetProcessById((int)processId); + if (process == null) + { + continue; + } + callback(new ProcessDetails(process, ptr) { Manageable = true }); @@ -637,18 +643,18 @@ public override bool Equals(object obj) { if (obj is Rect) { - return Equals((Rect) obj); + return Equals((Rect)obj); } if (obj is Rectangle) { - return Equals(new Rect((Rectangle) obj)); + return Equals(new Rect((Rectangle)obj)); } return false; } public override int GetHashCode() { - return ((Rectangle) this).GetHashCode(); + return ((Rectangle)this).GetHashCode(); } public override string ToString() @@ -666,6 +672,6 @@ public delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, public static extern uint GetProcessIdOfThread(IntPtr handle); [DllImport("user32.dll")] - public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags); + public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags); } } \ No newline at end of file