1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

VST3: Avoid potential memory allocations during buffer remapping

This commit is contained in:
reuk 2024-10-10 14:05:08 +01:00
parent ca8b5f7483
commit 1e902bcdee
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -1119,9 +1119,17 @@ public:
{
mappings = std::move (arrangements);
floatBusMap .resize (mappings.size());
doubleBusMap.resize (mappings.size());
busBuffers .resize (mappings.size());
const auto numBuses = mappings.size();
floatBusMap .resize (numBuses);
doubleBusMap.resize (numBuses);
busBuffers .resize (numBuses);
for (auto [index, busMap] : enumerate (mappings, size_t{}))
{
const auto numChannels = busMap.size();
floatBusMap [index].reserve (numChannels);
doubleBusMap[index].reserve (numChannels);
}
}
/* Applies the mapping to an AudioBuffer using JUCE channel layout. */
@ -1157,6 +1165,10 @@ private:
const ChannelMapping& busMap,
int channelStartOffset) const
{
// If this is hit, we may be about to allocate memory. Ideally, this should have been
// allocated in prepare().
jassert (busMap.size() <= bus.capacity());
bus.clear();
for (size_t i = 0; i < busMap.size(); ++i)