Skip to content

Commit

Permalink
prevent RTSS from searching for an entry if process has exited
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Jul 6, 2023
1 parent 3801dbc commit 23daf5f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions HandheldCompanion/Controls/ProcessEx.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ private static ProcessThread GetMainThread(Process process)
return mainThread;
}

public bool HasExited()
{
if (Process is not null)
return Process.HasExited;

return true;
}

public void Refresh()
{
if (Process.HasExited)
Expand Down
5 changes: 5 additions & 0 deletions HandheldCompanion/Managers/ProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public static ProcessEx GetProcess(int processId)
return null;
}

public static bool HasProcess(int pId)
{
return Processes.ContainsKey(pId);
}

public static List<ProcessEx> GetProcesses()
{
return Processes.Values.ToList();
Expand Down
16 changes: 10 additions & 6 deletions HandheldCompanion/Platforms/RTSS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,26 @@ private async void ProcessManager_ForegroundChanged(ProcessEx processEx, Process
if (ProcessId == 0)
return;

var HookTentative = 0;
do
{
/*
* loop until we either:
* - got an RTSS entry
* - process no longer exists
* - RTSS was closed
*/

try
{
appEntry = OSD.GetAppEntries().Where(x => (x.Flags & AppFlags.MASK) != AppFlags.None)
.FirstOrDefault(a => a.ProcessId == ProcessId);
appEntry = OSD.GetAppEntries().Where(x => (x.Flags & AppFlags.MASK) != AppFlags.None && x.ProcessId == ProcessId).FirstOrDefault();
}
catch (Exception)
{
}

HookTentative++;
catch {}

await Task.Delay(1000);
} while (appEntry is null && KeepAlive);
} while (appEntry is null && ProcessManager.HasProcess(ProcessId) && KeepAlive);

if (appEntry is null)
return;
Expand Down

0 comments on commit 23daf5f

Please sign in to comment.