I’m having a difficult time with the juce 5.4.5 combobox submenu deletion. I’m updating a older plugin and my preset browser uses a combobox. The combobox supports one-layer-down folder browsing by adding submenus to represent folders. The thing is that if I add the submenus from the stack in a function, they dangle. I’ve tried putting them in pointers/smart pointers/owned arrays/using release but they still dangle. I’ve even tried intentionally leaking them and that stops the dangling but on close the leak checker reports them. I’m using ComboBox::getrRootMenu()->addsubmenu.
The old version used
i.subMenu.reset (new PopupMenu (subMenu)) and pass by reference
the new version uses
i.subMenu.reset (new PopupMenu (std::move (subMenu))); and pass by value
In the new version the submenu seems like it getting deleted when the item’s std::unique_ptr goes out of scope and when the original is deleted. In the old version the item’s std::unique_ptr would take care of everything.
I’m sure im missing something obvious but I’m having a really hard time with this so any help would be appreciated.
ComboBox combo;
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
NewProjectAudioProcessor& processor;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NewProjectAudioProcessorEditor)
//==============================================================================
NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor (NewProjectAudioProcessor& p)
: AudioProcessorEditor (&p), processor §
{
addAndMakeVisible(combo);
PopupMenu pop = PopupMenu();
combo.getRootMenu()->addSubMenu(“sub”, pop);
// Make sure that before the constructor has finished, you’ve set the
// editor’s size to whatever you need it to be.
setSize (400, 300);
}
//==============================================================================
void NewProjectAudioProcessorEditor::paint (Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
void NewProjectAudioProcessorEditor::resized()
{
combo.setBounds(0, 0, 100, 100);
// This is generally where you’ll want to lay out the positions of any
// subcomponents in your editor…
}
The is just the projucers example project but with a combobox and an added sub menu. it you close the window for the plugin you will get a dangling pointer message from the leak detectot
I’m not seeing any leaked objects using this code. Are you sure you aren’t leaking a different object in your plug-in and you’re just seeing the leaked object detector firing on the menu because the other objects don’t have JUCE_LEAK_DETECTOR added to them?
Also, in the future you can format your code better on the forum by surrounding it with 3 backticks (```) like so: