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.
This commit is contained in:
Unknown W. Brackets 2021-10-09 08:24:54 -07:00
parent 01b99eff98
commit b77695c760

View file

@ -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)) {