Fix the actual Win7 launch crash (issue #22): empty send-mode list

The real cause — from the tester's crash stack, not my earlier (wrong)
System.ServiceProcess theory: ApplySendModeVisibility() is called early in the
MainForm constructor (via ApplyAsioMode), BEFORE the Input/Output tab populates
the send-mode ListBox. On Windows 7 process-loopback is unsupported, so it took
the `!supported` branch and set SelectedIndex on an EMPTY list, throwing
ArgumentOutOfRangeException ("value ('0') must be less than '0'") and crashing
at launch. On Windows 10/11 that branch is skipped (process-loopback IS
supported), which hid it from the gate and from every Win10/11 test.

.NET 10 genuinely runs on the tester's Win7 SP1 box (CoreLib 10.0.826 in the
crash) — so the earlier assembly-load theory was wrong; those Win7 changes were
addressing a non-problem. This is the fault.

Fix: guard the SelectedIndex set with `sendModeList.Items.Count > 0`. When the
list is empty there's nothing to reset (it's created selecting Devices, and this
runs again once the tab is built).

Test: "Main window builds where process-loopback is unsupported (issue #22)" —
forces ProcessLoopbackCapture.IsSupported = false (new ForceSupportedForTest
seam) and constructs the headless MainForm, so a Win10/11 box exercises the Win7
path. VERIFIED it reproduces: with the guard reverted the test fails with the
exact tester exception; with the guard it passes. Gate 34/34.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ednunp
2026-07-15 06:18:30 +01:00
co-authored by Claude Opus 4.8
parent 0567ea22c3
commit c482857314
3 changed files with 42 additions and 2 deletions
+26
View File
@@ -82,6 +82,7 @@ internal static class SelfTest
RunStep(results, "Auto-save non-read-only profiles (options + guard + silent timer)", AutoSaveNonReadOnlyProfiles);
RunStep(results, "Service verb gate (normal launch stays load-safe)", ServiceVerbGate);
RunStep(results, "Main window builds without loading the service assembly (Win7-safe)", MainWindowServiceAssemblyFree);
RunStep(results, "Main window builds where process-loopback is unsupported (Win7 launch, issue #22)", Win7SendModeConstruction);
RunStep(results, "Menu shortcuts don't clash with controls", MenuShortcutsDontClashWithControls);
RunStep(results, "Service log discovery (newest activity log)", ServiceLogDiscovery);
@@ -1449,6 +1450,31 @@ internal static class SelfTest
}
}
/// <summary>Issue #22: on Windows 7 process-loopback is unsupported, so ApplySendModeVisibility — called
/// early in the constructor (via ApplyAsioMode), BEFORE the Input/Output tab populates the send-mode
/// list — set SelectedIndex on an EMPTY ListBox and threw ArgumentOutOfRangeException, crashing the app
/// at launch. On Windows 10/11 the branch is skipped (process-loopback IS supported), which hid the bug
/// from the gate. This forces the unsupported path so the crash is reproduced (and now prevented) on a
/// Win10/11 test box.</summary>
private static string? Win7SendModeConstruction()
{
var prev = RemSound.Sender.ProcessLoopbackCapture.ForceSupportedForTest;
RemSound.Sender.ProcessLoopbackCapture.ForceSupportedForTest = false; // pretend we're on Windows 7
try
{
MainForm? mf = null;
Exception? ctorEx = null;
try { mf = new MainForm(null, RemSound.Core.Profile.NewBlank(), null, null, headless: true); }
catch (Exception ex) { ctorEx = ex; }
finally { mf?.Dispose(); }
Check(ctorEx is null,
$"constructing the main window with process-loopback unsupported (the Win7 path) must not throw — got {ctorEx?.GetType().Name}: {ctorEx?.Message}");
return "the main window constructs cleanly with process-loopback unsupported (Win7 send-mode path)";
}
finally { RemSound.Sender.ProcessLoopbackCapture.ForceSupportedForTest = prev; }
}
private static int FreeUdpPort()
{
using var s = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,