Skip to content

Commit

Permalink
fix: crash when process not found
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmd5 committed Feb 22, 2024
1 parent 76d8040 commit 3b94dea
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions BorderlessGaming/Logic/Windows/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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()
Expand All @@ -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);
}
}

0 comments on commit 3b94dea

Please sign in to comment.