Skip to content

Commit a3e668c

Browse files
author
Codeusa
committed
Fix crash
1 parent 7c338c2 commit a3e668c

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

BorderlessGaming.Logic/Core/ProcessWatcher.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,26 @@ private void UpdateProcesses()
205205
}
206206
Native.QueryProcessesWithWindows(pd =>
207207
{
208-
if (Config.Instance.IsHidden(pd.Proc.ProcessName))
208+
try
209209
{
210-
return;
210+
if (!string.IsNullOrWhiteSpace(pd?.Proc?.ProcessName))
211+
{
212+
if (Config.Instance.IsHidden(pd?.Proc?.ProcessName))
213+
{
214+
return;
215+
}
216+
if (Processes.Select(p => p.Proc.Id).Contains(pd.Proc.Id) &&
217+
Processes.Select(p => p.WindowTitle).Contains(pd.WindowTitle))
218+
{
219+
return;
220+
}
221+
Processes.Add(pd);
222+
_callback(pd, false);
223+
}
211224
}
212-
if (!Processes.Select(p => p.Proc.Id).Contains(pd.Proc.Id) ||
213-
!Processes.Select(p => p.WindowTitle).Contains(pd.WindowTitle))
225+
catch (Exception)
214226
{
215-
Processes.Add(pd);
216-
_callback(pd, false);
227+
_callback(null, false);
217228
}
218229
}, Processes.Where(p => p.WindowHandle != IntPtr.Zero).Select(p => p.WindowHandle).ToList());
219230
}

BorderlessGaming.Logic/Windows/Security.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ public static void SaveConfig(Config instance)
3636

3737
public static Config LoadConfigFile()
3838
{
39-
using (var memoryStream = new MemoryStream(File.ReadAllBytes(AppEnvironment.ConfigPath)))
39+
try
4040
{
41-
return Serializer.Deserialize<Config>(memoryStream);
41+
using (var memoryStream = new MemoryStream(File.ReadAllBytes(AppEnvironment.ConfigPath)))
42+
{
43+
return Serializer.Deserialize<Config>(memoryStream);
44+
}
45+
}
46+
catch (global::System.Exception)
47+
{
48+
File.Delete(AppEnvironment.ConfigPath);
49+
SaveConfig(new Config());
50+
return LoadConfigFile();
4251
}
4352
}
4453
}

BorderlessGaming/Forms/MainWindow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ private async void fullApplicationRefreshToolStripMenuItem_Click(object sender,
208208

209209
private void HandleProcessChange(ProcessDetails process, bool remove)
210210
{
211+
if (process == null)
212+
{
213+
return;
214+
}
211215
if (remove)
212216
{
213217
this.PerformSafely(() => lstProcesses.Items.Remove(process));

0 commit comments

Comments
 (0)