From fb1f94767deb95f5636ae6bc5d0f55e2da26b0da Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 15 Feb 2022 13:40:03 +0000 Subject: [PATCH] AU Host: Improve allocation checks If the block size changes from block to block, then it's possible for inputBuffer to be smaller than buffer, but for buffer to be smaller than the initially-allocated size of inputBuffer. --- .../format_types/juce_AudioUnitPluginFormat.mm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm index e6fdacfeb0..8389dd6c65 100644 --- a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm +++ b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm @@ -1101,8 +1101,9 @@ public: inMapping .setUpMapping (audioUnit, true); outMapping.setUpMapping (audioUnit, false); - inputBuffer.setSize (jmax (getTotalNumInputChannels(), getTotalNumOutputChannels()), - estimatedSamplesPerBlock); + preparedChannels = jmax (getTotalNumInputChannels(), getTotalNumOutputChannels()); + preparedSamples = estimatedSamplesPerBlock; + inputBuffer.setSize (preparedChannels, preparedSamples); } } @@ -1130,8 +1131,8 @@ public: void processAudio (AudioBuffer& buffer, MidiBuffer& midiMessages, bool processBlockBypassedCalled) { // If these are hit, we might allocate in the process block! - jassert (buffer.getNumChannels() <= inputBuffer.getNumChannels()); - jassert (buffer.getNumSamples() <= inputBuffer.getNumSamples()); + jassert (buffer.getNumChannels() <= preparedChannels); + jassert (buffer.getNumSamples() <= preparedSamples); // Copy the input buffer to guard against the case where a bus has more output channels // than input channels, so rendering the output for that bus might stamp over the input // to the following bus. @@ -1724,7 +1725,7 @@ private: AudioBuffer inputBuffer; Array> supportedInLayouts, supportedOutLayouts; - int numChannelInfos; + int numChannelInfos, preparedChannels = 0, preparedSamples = 0; HeapBlock channelInfos; AudioUnit audioUnit;