Trouble creating gain parameter for feedback in circular buffer

Whenever I replace 0.8, 0.8 in the copyFromWithRamp arguments with the variable gain and load the plugin in Ableton I’m getting extreme feedback. However, the buffer works as expected if I leave 0.8, 0.8 in place. I really don’t understand this behavior. I’m following along in this video

At 16:54 he replaces 0.8, 0.8 with gain, gain, with gain initialized to 0.3, however when I do this I get the infinite feedback. Ultimately, I’m trying to add a parameter to control the gain of the delay.

If it’s helpful to see the full code I’m working with I’ve created a git repository here.

void CircularBufferAudioProcessor::fillDelayBuffer(int channel, const int bufferLength, const int delayBufferLength, const float* bufferData, const float* delayBufferData)
{

    const float gain = 0.3;
    
        if (delayBufferLength > bufferLength + mWritePosition)
        {
            mDelayBuffer.copyFromWithRamp(channel, mWritePosition, bufferData, bufferLength, 0.8, 0.8);
        }
        else {
            const int bufferRemaining = delayBufferLength - mWritePosition;
            
            mDelayBuffer.copyFromWithRamp(channel, mWritePosition, bufferData, bufferRemaining, 0.8, 0.8);
            mDelayBuffer.copyFromWithRamp(channel, 0, bufferData, bufferLength - bufferRemaining, 0.8, 0.8);
        }
}