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.

This commit is contained in:
paulfd 2019-09-20 09:48:57 +02:00
parent d6d7eb73df
commit 27efcd029d

View file

@ -365,8 +365,8 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
::add<int>(sourcePosition, indices);
//FIXME : all this casting is driving me crazy
const auto sampleEnd = static_cast<int>(region->trueSampleEnd()) - 1;
if (region->shouldLoop() && static_cast<size_t>(sampleEnd) <= source.getNumFrames()) {
const auto sampleEnd = min(static_cast<int>(region->trueSampleEnd()), static_cast<int>(source.getNumFrames())) - 1;
if (region->shouldLoop() && region->loopRange.getEnd() <= source.getNumFrames()) {
const auto offset = sampleEnd - static_cast<int>(region->loopRange.getStart());
for (auto* index = indices.begin(); index < indices.end(); ++index) {
if (*index > sampleEnd) {