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.
This commit is contained in:
itsmattkc
2019-11-19 22:25:04 +09:00
parent 073176a45d
commit 8353b8d745
+8 -1
View File
@@ -68,7 +68,14 @@ void AudioBackend::ThreadCompletedCache(NodeDependency dep)
}
// Replace data with this data
memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast<size_t>(length));
int copy_length = qMin(length, cached_samples.size());
memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast<size_t>(copy_length));
if (copy_length < length) {
// Fill in remainder with silence
memset(pcm_data_.data() + offset + copy_length, 0, static_cast<size_t>(length - copy_length));
}
QFile f(CachePathName());
if (f.open(QFile::WriteOnly)) {