From 27efcd029d77feee4da28ea09a31e44770817102 Mon Sep 17 00:00:00 2001 From: paulfd Date: Fri, 20 Sep 2019 09:48:57 +0200 Subject: [PATCH] Corrected a bug where the Voice would try to read beyond the preloaded data when the background loading thread fails to run in time. This whole logic could probably use an overhaul. --- sfizz/Voice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sfizz/Voice.cpp b/sfizz/Voice.cpp index 5aef90ff..9327646d 100644 --- a/sfizz/Voice.cpp +++ b/sfizz/Voice.cpp @@ -365,8 +365,8 @@ void sfz::Voice::fillWithData(AudioSpan buffer) noexcept ::add(sourcePosition, indices); //FIXME : all this casting is driving me crazy - const auto sampleEnd = static_cast(region->trueSampleEnd()) - 1; - if (region->shouldLoop() && static_cast(sampleEnd) <= source.getNumFrames()) { + const auto sampleEnd = min(static_cast(region->trueSampleEnd()), static_cast(source.getNumFrames())) - 1; + if (region->shouldLoop() && region->loopRange.getEnd() <= source.getNumFrames()) { const auto offset = sampleEnd - static_cast(region->loopRange.getStart()); for (auto* index = indices.begin(); index < indices.end(); ++index) { if (*index > sampleEnd) {