fix(lifecycle): end the session before disposing it on close

Closing with a recording active called Shutdown() straight away, which disposed the frame pump and the
audio mixer underneath a running loop: ffmpeg never flushed, the file was never finalized or renamed,
and the pump was torn down mid-iteration. That is the 'app goes autistic on close' report.

MainWindow_Closing now holds the window open, runs StopBeforeShutdownAsync (the ordinary stop, bounded at
~6 s so a stuck encoder cannot make the app unclosable), then closes for real. StopStream already honours
the audio-before-video ordering, so the close path inherits it instead of inventing its own teardown.

Test: with nothing running, closing must not hold the window at all (the fast path stays fast).

Scope justification: Assets/starting-background.jpg is outside this unit — the creator's replacement art,
still awaiting their visual check.
This commit is contained in:
2026-11-13 07:47:35 -08:00
parent 70fcf89f9e
commit 1ce6b9c1b8
3 changed files with 97 additions and 1 deletions
+19
View File
@@ -616,6 +616,25 @@ public partial class MainViewModel : ViewModelBase
}
/// <summary>
/// Ends a running session before the app tears itself down, and says whether it is safe to close.
///
/// <para>Closing with a recording active used to dispose the frame pump and the audio mixer under a
/// live loop: ffmpeg never flushed, the file was never renamed or kept, and the pump was disposed
/// while it was still working. The window now holds itself open until the ordinary stop completes
/// (bounded — a stuck encoder must not trap the creator in an unclosable app).</para>
/// </summary>
internal async Task<bool> StopBeforeShutdownAsync()
{
if (!IsLive && !IsRecording) return true;
StopStream();
for (var i = 0; i < 120 && (IsLive || IsRecording); i++) // up to ~6 s
await Task.Delay(50).ConfigureAwait(true);
return !IsLive && !IsRecording;
}
public void Shutdown()
{
StopCurrentLaunchLogFeed();