Advice needed on when and where to dynamically change the oversampling factor, is this code OK..?

So is this now correct logic? (It doesn’t crash now).
I think I can make it more elegant than this but here’s how I altered it so far.

    juce::dsp::AudioBlock<float> originalBlock(buffer);     //assigned to original non-upsampled buffer
    juce::dsp::AudioBlock<float> block(buffer);   //block assigned to original non-upsampled buffer at start of processblock()
...
        if (//oversampling is on)   
        {
            block = oversamplingmodule->processSamplesUp(block);     //enlarge block of samples to process by the oversampling factor, and assign `block` to point to that upsampled block
        }
        int numSamplesToProcess = block.getNumSamples();
...
        for (int channel = 0; channel < totalNumInputChannels; ++channel)
        {
            auto* channelData = block.getChannelPointer(channel);     

            for (auto sample = 0; sample < numSamplesToProcess; sample++)
            {
...          //processing
...
        if (//oversampling is on) {                                //downsample if we've upsampled
            oversamplingmodule->processSamplesDown(originalBlock);     //block changed to originalblock
        }
...