From d354b991495f1bf7bdabd3a0316a561474f6966b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 17 Apr 2017 19:24:41 +0300 Subject: [PATCH] Fix crash. Valentina crashes when a user uses a tool and select button Cancel to close a tool dialog. --HG-- branch : release --- src/app/valentina/mainwindow.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index e926ba6f8..0895da04f 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -660,32 +660,18 @@ void MainWindow::ClosedDialogWithApply(int result, VMainGraphicsScene *scene) SCASSERT(not dialogTool.isNull()) if (result == QDialog::Accepted) { - // Only create tool if not already created with apply - if (dialogTool->GetAssociatedTool() == nullptr) - { - SCASSERT(scene != nullptr) - - dialogTool->SetAssociatedTool(DrawTool::Create(dialogTool, scene, doc, pattern)); - } - else - { // Or update associated tool with data - DrawTool * vtool= qobject_cast(dialogTool->GetAssociatedTool()); - SCASSERT(vtool != nullptr) - vtool->FullUpdateFromGuiApply(); - } + ApplyDialog(scene); } - SCASSERT(not dialogTool.isNull()) - QGraphicsItem *tool = dynamic_cast(dialogTool->GetAssociatedTool()); - SCASSERT(tool != nullptr) - ui->view->itemClicked(tool); + // If before Cancel was used Apply we have an item + DrawTool *vtool = qobject_cast(dialogTool->GetAssociatedTool());// Don't check for nullptr here if (dialogTool->GetAssociatedTool() != nullptr) { - DrawTool *vtool= qobject_cast(dialogTool->GetAssociatedTool()); SCASSERT(vtool != nullptr) vtool->DialogLinkDestroy(); connect(vtool, &DrawTool::ToolTip, this, &MainWindow::ShowToolTip); } ArrowTool(); + ui->view->itemClicked(vtool);// Don't check for nullptr here // If insert not to the end of file call lite parse if (doc->getCursor() > 0) { @@ -715,7 +701,7 @@ void MainWindow::ApplyDialog(VMainGraphicsScene *scene) } else { // Or update associated tool with data - DrawTool * vtool= qobject_cast(dialogTool->GetAssociatedTool()); + DrawTool * vtool = qobject_cast(dialogTool->GetAssociatedTool()); SCASSERT(vtool != nullptr) vtool->FullUpdateFromGuiApply(); }