Strange DialogWindow crashes

I have this code in my Component:

// CommonDialog _commonDialog in .h file -- component to be shown in modal dialog;
    _commonDialog.reset(new CommonDialog());
    _commonDialog->setSize(400, 200);
    _commonDialog->setDialogText(T::t("Are you sure you want to delete this instance?"));

    //std::unique_ptr<DialogWindow::LaunchOptions> o  in .h file;
    o.reset(new DialogWindow::LaunchOptions());
    o->useNativeTitleBar = true;

    //std::unique_ptr<DialogWindow> dialogWindow  in .h file;

It works fine.
But when I close my application, it crashes. I don’t understand why?

The debugger stack trace looks like this:

Well, if I read your code correctly, you are using o->content.setOwned on a unique_ptr. By calling “setOwned” you are telling the content to delete the _commonDialog, once the window closes. But at the same time, the unique_ptr is also going to try and delete the _commonDialog, once you close the application. So basically two different “holders” are both trying to delete the same object.

Try this: Either use o.content->nonOwned() or just use a non-smart pointer for _commonDialog.

1 Like

Thank you! nonOwned works. You saved me hours.