From b77695c760ba8dde18f94f2e87f56546e30bfa57 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 9 Oct 2021 08:24:54 -0700 Subject: [PATCH] Audio: Protect against time skew. It might be possible a clock is adjusting backwards slightly after a time update, and this could've caused sz to become negative. Based on crash reports. --- UI/BackgroundAudio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index 82d7bf586d..5db580ffcd 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -344,7 +344,10 @@ int BackgroundAudio::Play() { } double now = time_now_d(); - int sz = lastPlaybackTime_ <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime_) * 44100); + int sz = 44100 / 60; + if (lastPlaybackTime_ > 0.0 && lastPlaybackTime_ >= now) { + sz = (int)((now - lastPlaybackTime_) * 44100); + } sz = std::min(BUFSIZE / 2, sz); if (at3Reader_) { if (at3Reader_->Read(buffer, sz)) {