Plugin not always picking up the correct channel configurations

Hi All.

Bit of an odd one but for some reason one of my plugins has a bug where sometimes it doesn’t pick up the correct channel configurations (most of the time it works fine). Sometimes it only passes audio out one side/sometimes it doesn’t pass audio at all. The way to resolve it is to reload the plugin either by removing it from a project and re-adding it or by reloading the whole project. It’s an effect plugin so (mostly) doesn’t generate its own audio.

I’d be extremely grateful if anyone has any ideas.

The stuff that is relevant to channels are -

In prepareToPlay:

dsp::ProcessSpec spec;
spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlock;
spec.numChannels = getMainBusNumOutputChannels();

In isBusesLayoutSupported (I don’t think I have changed the default):

#ifndef JucePlugin_PreferredChannelConfigurations
bool TapeAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
  #if JucePlugin_IsMidiEffect
    ignoreUnused (layouts);
    return true;
  #else
    // This is the place where you check if the layout is supported.
    // In this template code we only support mono or stereo.
    if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
     && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
        return false;

    // This checks if the input layout matches the output layout
   #if ! JucePlugin_IsSynth
    if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
        return false;
   #endif

    return true;
  #endif
}
#endif

For my processing in processBlock I am just using “buffer.getNumChannels()” wherever it is needed.