ComboBox subMenu deletion in 5.4.5

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.

Im still having issues with this. If anyone has any idea please let me know

It’s hard to say what could be going wrong without seeing any code. Can you post a minimal example which reproduces the issue?

  • ==============================================================================

    This file was auto-generated!

    It contains the basic framework code for a JUCE plugin editor.

    ==============================================================================
    */

#pragma once

#include “…/JuceLibraryCode/JuceHeader.h”
#include “PluginProcessor.h”

//==============================================================================
/**
*/
class NewProjectAudioProcessorEditor : public AudioProcessorEditor
{
public:
NewProjectAudioProcessorEditor (NewProjectAudioProcessor&);
~NewProjectAudioProcessorEditor();

//==============================================================================
void paint (Graphics&) override;
void resized() override;

private:

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)

};

  • ==============================================================================

    This file was auto-generated!

    It contains the basic framework code for a JUCE plugin editor.

    ==============================================================================
    */

#include “PluginProcessor.h”
#include “PluginEditor.h”

//==============================================================================
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);
}

NewProjectAudioProcessorEditor::~NewProjectAudioProcessorEditor()
{
}

//==============================================================================
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));

g.setColour (Colours::white);
g.setFont (15.0f);
g.drawFittedText ("Hello World!", getLocalBounds(), Justification::centred, 1);

}

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:

<code>

I’m running the plugin in debug mode as a vst3 in audio plugin host. If you run it stand alone then the bug wont show up.

This what the console says

***** Dangling pointer deletion! Class: PopupMenu**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:66**

heres the stack trace

OK, this should now be fixed in baebb9d.

Very grateful. This one had me truly stumped. Thank you very much ed95, you are the best!