Skip to content

Commit 3b94dea

Browse files
committed
fix: crash when process not found
1 parent 76d8040 commit 3b94dea

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

BorderlessGaming/Logic/Windows/Native.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using BorderlessGaming.Logic.Models;
1111
using BorderlessGaming.Logic.Misc.Utilities;
1212
using BorderlessGaming.Logic.Windows.Audio;
13+
using BorderlessGaming.Logic.Extensions;
1314

1415
namespace BorderlessGaming.Logic.Windows
1516
{
@@ -340,7 +341,7 @@ private static bool GetMainWindowForProcess_EnumWindows(IntPtr hWndEnumerated, u
340341
{
341342
if (IsWindowVisible(hWndEnumerated))
342343
{
343-
if ((uint) styleCurrentWindow_standard != 0)
344+
if ((uint)styleCurrentWindow_standard != 0)
344345
{
345346
GetMainWindowForProcess_Value = hWndEnumerated;
346347
return false;
@@ -440,7 +441,12 @@ bool Del(IntPtr hwnd, uint lParam)
440441
}
441442
uint processId;
442443
GetWindowThreadProcessId(ptr, out processId);
443-
callback(new ProcessDetails(Process.GetProcessById((int)processId), ptr)
444+
var process = ProcessExtensions.GetProcessById((int)processId);
445+
if (process == null)
446+
{
447+
continue;
448+
}
449+
callback(new ProcessDetails(process, ptr)
444450
{
445451
Manageable = true
446452
});
@@ -637,18 +643,18 @@ public override bool Equals(object obj)
637643
{
638644
if (obj is Rect)
639645
{
640-
return Equals((Rect) obj);
646+
return Equals((Rect)obj);
641647
}
642648
if (obj is Rectangle)
643649
{
644-
return Equals(new Rect((Rectangle) obj));
650+
return Equals(new Rect((Rectangle)obj));
645651
}
646652
return false;
647653
}
648654

649655
public override int GetHashCode()
650656
{
651-
return ((Rectangle) this).GetHashCode();
657+
return ((Rectangle)this).GetHashCode();
652658
}
653659

654660
public override string ToString()
@@ -666,6 +672,6 @@ public delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType,
666672
public static extern uint GetProcessIdOfThread(IntPtr handle);
667673

668674
[DllImport("user32.dll")]
669-
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
675+
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
670676
}
671677
}

0 commit comments

Comments
 (0)