Hello,
I am making a plugIn with several filters, each filter is in a class that inherits from component so it is able to process samples but also it can be displayed by its own so I can easily add several filters on the GUI as “cards”.
To do this I use a OwnedArray like so :
OwnedArray<myClass> filters;
then in the editor I fill it and make each of them visible in a loop like so :
myClass newFilter1 = myClass();
myClass newFilter2 = myClass();
audioProcessor.filters.add(&newFilter1);
audioProcessor.filters.add(&newFilter2);
for (size_t i = 0; i < audioProcessor.filters.size(); ++i)
{
addAndMakeVisible(audioProcessor.filters[i]);
}
but where it go wrong is in the resized function :
void InterpolationFilterAudioProcessorEditor::resized()
{
int numberOfCards = audioProcessor.filters.size();
float w = getWidth();
float h = getHeight();
float cardWidth = w / numberOfCards;
for (size_t i = 0; i < numberOfCards; ++i)
{
if (audioProcessor.filters[i] != nullptr)
{
audioProcessor.filters[i]->setBounds(i * cardWidth, 0, cardWidth, h);
}
}
}
The issue comes from the : audioProcessor.filters[i]->setBounds(...
part.
The standalone app does open but it does not display anything (I just put a label on each filter that should be on screen), then when I resize the window it crashes.
I think this is very much related to this topic that says it is related to nullptr and undefined behavior:
https://forum.juce.com/t/exc-bad-access-when-setting-bounds/25918/3
but I couldn’t figure out a way to correct my code by reading it.
Can anyone figure it out ?