From 8bac5c259a6717fbc8569f1b91ec4965c2b453b8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 22 Jun 2021 17:06:30 -0700 Subject: [PATCH] Trycatch sound stop, only stop if a sound has been played Closes #3224 mono's impl of soundplayer is different, hence the need to be a little safer here. https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/System/System.Media/SoundPlayer.cs#L255 https://referencesource.microsoft.com/#System/sys/system/Media/SoundPlayer.cs,455 --- PKHeX.WinForms/Controls/Slots/CryPlayer.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/PKHeX.WinForms/Controls/Slots/CryPlayer.cs b/PKHeX.WinForms/Controls/Slots/CryPlayer.cs index 737dd0aff..7507b1ea2 100644 --- a/PKHeX.WinForms/Controls/Slots/CryPlayer.cs +++ b/PKHeX.WinForms/Controls/Slots/CryPlayer.cs @@ -26,7 +26,16 @@ public void PlayCry(ISpeciesForm pk, int format) #pragma warning restore CA1031 // Do not catch general exception types } - public void Stop() => Sounds.Stop(); + public void Stop() + { + if (string.IsNullOrWhiteSpace(Sounds.SoundLocation)) + return; + + try { Sounds.Stop(); } +#pragma warning disable CA1031 // Do not catch general exception types + catch { Debug.WriteLine("Failed to stop sound."); } +#pragma warning restore CA1031 // Do not catch general exception types + } private static string GetCryPath(ISpeciesForm pk, string cryFolder, int format) {