Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application freezes after returning from Lock screen #680

Open
2 tasks done
usagirei opened this issue Jul 10, 2024 · 0 comments
Open
2 tasks done

Application freezes after returning from Lock screen #680

usagirei opened this issue Jul 10, 2024 · 0 comments
Labels

Comments

@usagirei
Copy link

Requirements

  • This issue doesn't already exist
  • This bug is Not related to compatability with a specific game

Summary

Borderless Gaming will freeze when you lock the computer screen, possibly in other scenarios that fit the same criteria.

Steps to reproduce

  1. Run Application
  2. Go to lock screen windows (Win+L), and wait a few moments (10~15 seconds should do it, if not lock it again and retry)
  3. Come back to frozen application

Technical details

  1. GetForegroundWindow may return NULL under certain conditions, one of which, is when the lock screen is active.

  2. Then GetWindowThreadProcessId will return NULL too (Which happens to be a valid PID, the System Idle process) ,

  3. Then when it tries to create a ProcessDetails class, for an invalid process, which tries to get the window title for an invalid window.

    var handle = Native.GetForegroundWindow();
    Native.GetWindowThreadProcessId(handle, out uint processId);
    var details = new ProcessDetails(Process.GetProcessById((int)processId), handle);

  4. It will then hang indefinitely trying to do so here:

    if (!Native.IsWindow(_windowHandle))
    {
    _windowHandle = Native.GetMainWindowForProcess(Proc).GetAwaiter().GetResult();
    }


Checks for NULL/Invalid handles need to be introduced:

An early return here:

var handle = Native.GetForegroundWindow();

var handle = Native.GetForegroundWindow(); 
if(handle == IntPtr.Zero) 
    return;

And maybe a short circuit here:

if (!Native.IsWindow(_windowHandle))
{
_windowHandle = Native.GetMainWindowForProcess(Proc).GetAwaiter().GetResult();
}

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

version

9.5.6.1328 - git 3cc4dc6

@usagirei usagirei added the bug label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant