From 8353b8d7453f065cf6057743736480ad4e251463 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 19 Nov 2019 22:19:18 +0900 Subject: [PATCH] handle node providing less audio samples than expected for a given time If the bytes retrieved is less than the bytes we expected for the time period we're rendering, we fill the remainder with silence. Fixes segfault trying to copy bytes that aren't actually allocated. --- app/render/backend/audio/audiobackend.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/render/backend/audio/audiobackend.cpp b/app/render/backend/audio/audiobackend.cpp index 4336ceff4..0521d75a5 100644 --- a/app/render/backend/audio/audiobackend.cpp +++ b/app/render/backend/audio/audiobackend.cpp @@ -68,7 +68,14 @@ void AudioBackend::ThreadCompletedCache(NodeDependency dep) } // Replace data with this data - memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast(length)); + int copy_length = qMin(length, cached_samples.size()); + + memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast(copy_length)); + + if (copy_length < length) { + // Fill in remainder with silence + memset(pcm_data_.data() + offset + copy_length, 0, static_cast(length - copy_length)); + } QFile f(CachePathName()); if (f.open(QFile::WriteOnly)) {