Why is NOutChansConnected equal to 0?

I’m a beginner to iPlug, and have made a filter plugin as a test. What I’ve noticed is, if I get the value of NOutChansConnected() in the ProcessBlock function, I get the correct result. However, if I do the same in the IPlugEffect function, I get a result of 0.

When the plugin loads, I want to create my Filter object and construct it using the value of NOutChansConnected(). So, I thought I’d set it up in the IPlugEffect function, where it seems all other variables are set up. Something like this:

Filter *filter;

IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
    const int nChans = NOutChansConnected();
    filter = new Filter(nChans);

Unfortunately, it doesn’t work. If I manually set nChans to 2, the plugin runs correctly. I’ve tried it in GarageBand and also in a VST host application called vPlayer. It crashes in both unless I set nChans to 2 rather than using NOutChansConnected().

I’m sure I’m doing something wrong! Your help is greatly appreciated :slight_smile:

A plug-ins I/O are not yet connected in the plug-in constructor. You can override IPlugProcessor::OnActivate() to do something when the I/O connections are known.

1 Like