ComboBox.addItem() exception thrown

This must be silly but I’m lost.
I just have declare a ComboBox:

private:
    ComboBox filterTypeMenu;

And added

void CircularAudioBufferAudioProcessorEditor::paint (juce::Graphics& g)
{
   filterTypeMenu.addItem("Lowpass", 1);
    filterTypeMenu.addItem("HighPass", 2);
    filterTypeMenu.setText("Filter Type:", dontSendNotification);
    addAndMakeVisible(filterTypeMenu);
}

But after building it myProject.exe triggers a breakpoint in this bit of code from the comboBox:

// you shouldn't use duplicate item IDs!
    jassert (getItemForId (newItemId) == nullptr);

I don’t understand why this happens if no comboBox ID is duplicated.

Someone knows why this could be happening?

You should not be doing this in ‘paint’. It is getting called repeatedly, and it is adding the items each time. So, on the second call you ARE duplicating the IDs. All of that code should probably go in the constructor

1 Like

You are right. Thanks so much

Raul