Open usagirei opened 3 months ago
Borderless Gaming will freeze when you lock the computer screen, possibly in other scenarios that fit the same criteria.
GetForegroundWindow may return NULL under certain conditions, one of which, is when the lock screen is active.
Then GetWindowThreadProcessId will return NULL too (Which happens to be a valid PID, the System Idle process) ,
Then when it tries to create a ProcessDetails class, for an invalid process, which tries to get the window title for an invalid window. https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Windows/ForegroundManager.cs#L33-L35
It will then hang indefinitely trying to do so here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Models/ProcessDetails.cs#L56-L59
Checks for NULL/Invalid handles need to be introduced:
An early return here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Windows/ForegroundManager.cs#L33
var handle = Native.GetForegroundWindow(); if(handle == IntPtr.Zero) return;
And maybe a short circuit here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Models/ProcessDetails.cs#L56-L59
if ((_windowHandle != IntPtr.Zero) && !Native.IsWindow(_windowHandle)) { _windowHandle = Native.GetMainWindowForProcess(Proc).GetAwaiter().GetResult(); }
Or ensure a ProcessDetails class can't be created for an invalid process/window
9.5.6.1328 - git 3cc4dc6
Requirements
Summary
Borderless Gaming will freeze when you lock the computer screen, possibly in other scenarios that fit the same criteria.
Steps to reproduce
Technical details
GetForegroundWindow may return NULL under certain conditions, one of which, is when the lock screen is active.
Then GetWindowThreadProcessId will return NULL too (Which happens to be a valid PID, the System Idle process) ,
Then when it tries to create a ProcessDetails class, for an invalid process, which tries to get the window title for an invalid window. https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Windows/ForegroundManager.cs#L33-L35
It will then hang indefinitely trying to do so here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Models/ProcessDetails.cs#L56-L59
Checks for NULL/Invalid handles need to be introduced:
An early return here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Windows/ForegroundManager.cs#L33
And maybe a short circuit here: https://github.com/Codeusa/Borderless-Gaming/blob/3cc4dc6bd580b263287be45981f1e36036daf4eb/BorderlessGaming.Logic/Models/ProcessDetails.cs#L56-L59
Or ensure a ProcessDetails class can't be created for an invalid process/window
version
9.5.6.1328 - git 3cc4dc6