ProcessSpec and numChannels problem

Hi there, how’s everyone?
I have a compressor class that I’m initializing in the audioProcessor’s prepareToPlay with a processSpec.
Then, in the compressor’s prepare function I initialize all of the buffers, oversampling, etc with that processSpec.

The plugin works just fine when using it on a stereo track, but as soon as I open it up on a mono track, it crashes and I get this jassert in the AudioBuffer class:
jassert (isPositiveAndBelow (channelNumber, numChannels));
The way I managed to fix it for now is by manually setting the numChannels to 2 in the setSize() method of the buffer like so:
mainBuffer.setSize(2, spec.maximumBlockSize);

Is this the right approach or may doing this create problems?

Thanks a ton!

i was once told the vst standard does not forbid a host to just randomly let a plugin switch from mono to stereo or back, if it wanted to, as long as the plugin allows both channel configurations. i think that’s stupid, because in all DAWs i know you can already tell if a plugin has to work in mono or stereo at initialization, cause it’s defined by the track you init it on, but hey, that’s just what the spec says, so what you are doing is in fact good practice. let’s just hope someone actually makes a DAW that modulates between mono and stereo on a track dynamically one day so it’s worth it, even though i have no idea what that would be useful for

Ha! Alright, that is good to know then!
Thanks a lot!

i think that’s stupid, because in all DAWs i know you can already tell if a plugin has to work in mono or stereo at initialization,

You can’t actually because the plugin might not even be outputting to the same “track” at all (eg, multi output plugins). There’s also the entire scope of upmixing and downmixing where your plugin is going to have a different I/O configuration for its inputs and outputs (eg upmixing stereo to surround, or vice versa).

The VST3 spec’s i/o configuration dance is extremely complicated because it’s a complicated problem domain.