Allow to re-allocate (ensure) buffers after clearing them

This fixes a crash when removing and re-adding regionFX.

Removing all FX clears the _readcache BufferSet
(see AudioRegion::remove_plugin).

BufferSet::clear() calls _buffers.clear(); leading to a assert/crash
when adding a new regionFX plugin which calls BufferSet::ensure_buffers.
This commit is contained in:
Robin Gareus 2025-09-23 17:44:54 +02:00
parent afd0172c63
commit e539cabc00
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04

View file

@ -155,12 +155,20 @@ void
BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
{
assert(type != DataType::NIL);
assert(type < _buffers.size());
assert(type < _buffers.capacity());
if (num_buffers == 0) {
return;
}
/* after a clear (), re-initlaize buffers */
if (_buffers.empty ()) {
for (size_t i=0; i < DataType::num_types; ++i) {
_buffers.push_back(BufferVec());
}
}
assert(_buffers.size() == DataType::num_types);
// The vector of buffers of the type we care about
BufferVec& bufs = _buffers[type];