From 5a020c1e9e5a9f2171a39decef94155cca4d6450 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:47:39 -0700 Subject: [PATCH] Prevent crash in SoundOutputProvider due to negative sample count being computed In practice this doesn't occur ever except with subframe core abuse with tiny sample counts being spammed --- .../Sound/Utilities/SoundOutputProvider.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/Sound/Utilities/SoundOutputProvider.cs b/src/BizHawk.Client.Common/Sound/Utilities/SoundOutputProvider.cs index 7fc8ba96d8..c753af739b 100644 --- a/src/BizHawk.Client.Common/Sound/Utilities/SoundOutputProvider.cs +++ b/src/BizHawk.Client.Common/Sound/Utilities/SoundOutputProvider.cs @@ -263,7 +263,11 @@ namespace BizHawk.Client.Common // would drift by ~22 milliseconds per minute. _resampleLengthRoundingError = newCountExact - count; - AddSamplesToBuffer(samples, count); + if (count > 0) + { + // in rare cases (with subframe core tiny sample spam) count can be negative, somehow + AddSamplesToBuffer(samples, count); + } } private static double CalculatePowerMean(IEnumerable values, double power)