tempChannels in VST 2 wrapper

In the VST Wrapper ProcessReplacing metyhod there is the following code:

float* chan = tempChannels.getUnchecked(i);
if (chan == nullptr)
    chan = outputs[i];
    // if some output channels are disabled, some hosts supply the same buffer
    // for multiple channels - this buggers up our method of copying the
    // inputs over the outputs, so we need to create unique temp buffers in this case..
    for (int j = i; --j >= 0;)
        if (outputs[j] == chan)
            chan = new float [blockSize * 2];
            tempChannels.set (i, chan);

I do not like the dynamic allocation in the audio thread, but this is not my biggest concern about this code.

I do not understand well the comment. Why directly copying the input into the output won't work even if some buffers given by the host are the same because of disabled channels. 

In my case it seems to work well without these tempChannels but since I am not using the input and always memest the output to 0 before processing I do not see the problem.



The allocation will only happen the first time the block is called, and only if those hosts which behave in this annoying way. 

Imagine if the host provides 2 inputs and 2 outputs, but gives the same pointer for both of the output channels. Normally juce will copy each input channel into its corresponding output channel, then give you those two output pointers for your plugin to modify. But they'll be the same buffer, so obviously you'll have lost one of the input channels. But like the comment says, not all hosts do that, and hopefully the workaround will rarely be needed.

Even if this happens only once, this is not a good thing. Having preallocated buffers could be better.

In my case the problem is that the host is giving dummy buffers until the user set manually an output to the plugin. After that the host gives valid buffers.

In this case the workaround is not working because the tempChannels has been allocated once, then the test:

if(chan != nullptr)

is always false and chan is never assigned to the output given by the host.