Weird behaviour on Oscilloscope

Hi, I’m a beginner and I’ve been working on this Oscilloscope for a while and trying get my hands on different aspects of the plugin programming as sharing data between threads and it has been a little difficult as I’m not so good in C++. I have this experiment based on the JUCE tutorial on FFT. and it’s giving me this kind of glitches when the editor opens.

Thanks in advance if you can give me useful advice.

Vídeo sin título ‐ Hecho con Clipchamp

//PluginProcessor.h
    void pushNextSampleIntoFifo(float sample);

    static constexpr auto fifoSize = 1024;

    std::array<float, fifoSize> fifo;
    std::array<float, fifoSize*2> oscData;
    int fifoIndex = 0;
//PluginProcessor.cpp
void AudioPluginAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer,
                                             juce::MidiBuffer &midiMessages)
{
    juce::ignoreUnused(midiMessages);
    juce::ScopedNoDenormals noDenormals;

    auto *channelData = buffer.getReadPointer(0);
    for (int i = 0; i < buffer.getNumSamples(); ++i)
    {
        if(i%10==0)
        pushNextSampleIntoFifo(channelData[i]);
    }
}
void AudioPluginAudioProcessor::pushNextSampleIntoFifo(float sample)
{
    if (fifoIndex == fifoSize)
    {
        std::fill(oscData.begin(), oscData.end(), 0.0f);
        std::copy(fifo.begin(), fifo.end(), oscData.begin());
        fifoIndex = 0;
    }
    fifo[(size_t) fifoIndex++] = sample;
}
//PluginEditor.cpp

void AudioPluginAudioProcessorEditor::paint(juce::Graphics &g)
{
    std::cout<< processorRef.fifoIndex << std::endl;
    juce::Path waveform;
    waveform.startNewSubPath(0, (float) getHeight() / 2);
    float height = static_cast<float>(getLocalBounds().getHeight());
    float width = static_cast<float>(getLocalBounds().getWidth());
    for (int i = 0; i < 1024; ++i) {
        float mappedSample = height/2- processorRef.oscData[i]*height;
        float xposition = (float) i / 1024 * width;
        waveform.lineTo(xposition, mappedSample);
    }
    g.fillAll(juce::Colours::black);
    g.setColour(juce::Colours::white);
    g.strokePath(waveform, juce::PathStrokeType(1.f,
                                                juce::PathStrokeType::curved,
                                                juce::PathStrokeType::EndCapStyle::rounded));
}
void AudioPluginAudioProcessorEditor::timerCallback()
{
    repaint();
}