Sidechain crash for mono to stereo layout in Pro Tools

Hi,

I’ve been running some tests with a SC implementation inside a plugin. It works perfectly in Reaper and Logic Pro. I also tested it in Pro Tools and found that it works correctly with mono-to-mono and stereo-to-stereo configurations. However, when testing a mono-to-stereo configuration, Pro Tools crashes as soon as I change the key input or sometimes even just loading the plugin.

I’ve tried debugging the issue, but it only shows a disassembly view. I suspect there may be an invalid read or write operation in my processor, but I haven’t been able to identify where it might be happening.

Note: I have also test mono to stereo inside Logic Pro, and it works great, not an issue.

This is my busesProperties:

 return BusesProperties()
        .withInput("Input", juce::AudioChannelSet::stereo(), true)
        .withOutput("Output", juce::AudioChannelSet::stereo(), true)
        .withInput("Sidechain", juce::AudioChannelSet::stereo(), true);

Then my isBusesLayoutSupported()

 if(layouts.getMainInputChannelSet() == juce::AudioChannelSet::disabled()
       || layouts.getMainOutputChannelSet() == juce::AudioChannelSet::disabled()) {
        return false;
    }

    // This plugin only supports mono to mono/stereo or stereo to stereo with either mono or stereo SC
    const int inputs = layouts.getNumChannels(true, 0);
    const int outputs = layouts.getNumChannels(false, 0);
    const int scInputs = layouts.getNumChannels(true, 1);

    // AAX plugins change their number of inputs if they don't have the key input activated
    if((inputs == 1 && scInputs <= 2 && outputs <= 2) || (inputs == 2 && scInputs <= 2 && outputs == 2))
        return true;

    return false;

My prepareToPlay is set to:

 const int numInputChannels = getChannelCountOfBus(true, 0);
    const int numOutputChannels = getChannelCountOfBus(false, 0);
    const int numSCInputChannels = getChannelCountOfBus(true, 1);
    const int totalNumInputChannels = getTotalNumInputChannels();

  isM2SArrangement = false;
        if(numInputChannels == 1 && numOutputChannels == 2) {
            isM2SArrangement = true;
        }
        isExtSCEnable = numSCInputChannels > 0;
        isMonoWithStereoSC = false;
        if(numInputChannels == 1 && numOutputChannels == 1 & 
           numSCInputChannels == 2) {
            isMonoWithStereoSC = true;
        }

Also, prepareToPlay is called everytime either number of inputs/outpus/sc has change

Then in my processBlock()

for(int ch = 0; ch < numInputChannels + numSCInputChannels; ch++) {
        inPtr[ch] = inputs[ch];
    }

//Prepare SC inputs
        for(int ch = 0; ch < numInputChannels; ch++) {
            dryCh[ch] = (*inPtr[ch]++);
        }
        if(isM2SArrangement)
            dryCh[1] = dryCh[0];

        if(isExtSCEnable) {
            exScCh[0] = (*inPtr[numInputChannels]++);
            exScCh[1] = (numSCInputChannels > 1) ? (*inPtr[numInputChannels + 1]++) : exScCh[0];
            if(isMonoWithStereoSC)
                exScCh[0] = (exScCh[0] + exScCh[1]) * 0.5;
        } else {
            for(int ch = 0; ch < channelCount; ch++) {
                exScCh[ch] = dryCh[ch];
            }
        }

Thank you all.