Fix: Rare Potential Crash/Null Reference

- Fixes a rare issue where the application could crash if the same window was called by multiple parts of the program at the same time. This could cause unexpected errors or crashes.
This commit is contained in:
Frog
2026-06-01 23:44:09 -07:00
parent 94bec38bd0
commit 69d29d6863
2 changed files with 18 additions and 6 deletions
+9 -3
View File
@@ -9,6 +9,7 @@ namespace CreamInstaller.Forms;
internal sealed partial class DebugForm : CustomForm
{
private static DebugForm current;
private static readonly object currentLock = new();
private Form attachedForm;
@@ -22,9 +23,14 @@ internal sealed partial class DebugForm : CustomForm
{
get
{
if (current is not null && (current.Disposing || current.IsDisposed))
current = null;
return current ??= new();
lock (currentLock)
{
if (current is null || current.Disposing || current.IsDisposed)
{
current = new DebugForm();
}
return current;
}
}
}
+9 -3
View File
@@ -25,6 +25,7 @@ internal sealed partial class SelectForm : CustomForm
private const string HelpButtonListPrefix = "\n • ";
private static SelectForm current;
private static readonly object currentLock = new();
private readonly ConcurrentDictionary<string, string> remainingDLCs = new();
@@ -43,9 +44,14 @@ internal sealed partial class SelectForm : CustomForm
{
get
{
if (current is not null && (current.Disposing || current.IsDisposed))
current = null;
return current ??= new();
lock (currentLock)
{
if (current is null || current.Disposing || current.IsDisposed)
{
current = new SelectForm();
}
return current;
}
}
}