DocumentWindow crashes when exiting

Hello,
My main window is
class MainComponent : public AudioAppComponent, public Slider::Listener, public ComboBox::Listener, public TextButton::Listener, public TextEditor::Listener

I created another DocumentWindow as a Dialog Window inside that MainComponent

DocumentWindow* combowindow = new DocumentWindow(“ComboWindow”, Colour::Colours::white, DocumentWindow::allButtons, false)

Also I created a component

Component combocontent;

I inserted several buttons, text editors etc inside that combocontent

And

combowindow->setContentOwned(&combocontent, false);

So I use this combowindow as a dialog popup window

But, when I exit this program

delete combowindow;

This causes crashes

So I tried

combocontent.removeAllChildren();

combowindow->clearContentComponent();

It does not work. The program crashes

+++++++++++++++++===================================**************************
More precisely it crashes here

void ResizableWindow::clearContentComponent()
{
if (ownsContentComponent)
{
contentComponent.deleteAndZero();
}
else
{
removeChildComponent (contentComponent);
contentComponent = nullptr;
}
}

+++++++++++++++++===================================**************************

So, could you please teach me how to handle this properly

Thank you

Hello,
I found the coding below works OK now

combowindow->setContentNonOwned(& combocontent, false);

not the original

combowindow->setContentOwned(&combocontent, false);

So, could you please explain to me what is the difference and why this happens?

Thanks

The differences are explained in the documentation for these functions. The “Owned” variant will call delete on the component once it is no longer needed, so should only be used with components created via new. The “NonOwned” variant will not delete the component.

The crash you’re seeing is likely because the ResizableWindow is attempting to delete an object that wasn’t created via new.

1 Like

Thank you. Have a nice day !