From 08682d8b53ea7d333ec4554d81bd59fb61e71a5b Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Thu, 22 Oct 2015 17:18:37 +0200 Subject: [PATCH] Avoid a 'Segmentation violation' when pasting a destroyed object. --- src/genericgui/GenericGui.cxx | 8 ++++++++ src/genericgui/GuiEditor.cxx | 2 ++ src/genericgui/QtGuiContext.cxx | 3 +++ src/hmi/guiObservers.cxx | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/src/genericgui/GenericGui.cxx b/src/genericgui/GenericGui.cxx index 09f6f813b..67d02f581 100644 --- a/src/genericgui/GenericGui.cxx +++ b/src/genericgui/GenericGui.cxx @@ -2555,7 +2555,11 @@ void GenericGui::onUndo() { DEBTRACE("GenericGui::onUndo"); if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty()) + { QtGuiContext::getQtCurrent()->getInvoc()->undo(); + // Empty the clipboard in order to avoid the copy of a destroyed object. + QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL); + } else Message("undo not possible when there are local modifications not confirmed"); } @@ -2563,7 +2567,11 @@ void GenericGui::onRedo() { DEBTRACE("GenericGui::onRedo"); if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty()) + { QtGuiContext::getQtCurrent()->getInvoc()->redo(); + // Empty the clipboard in order to avoid the copy of a destroyed object. + QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL); + } else Message("redo not possible when there are local modifications not confirmed"); } diff --git a/src/genericgui/GuiEditor.cxx b/src/genericgui/GuiEditor.cxx index abf13197c..ecbe765d4 100644 --- a/src/genericgui/GuiEditor.cxx +++ b/src/genericgui/GuiEditor.cxx @@ -456,6 +456,8 @@ void GuiEditor::DeleteSubject(Subject* parent, toRemove->askRegisterUndoDestroy(); if(!parent->destroy(toRemove)) Message mess; + // Empty the clipboard in order to avoid the copy of a destroyed object. + QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL); } void GuiEditor::CutSubject() diff --git a/src/genericgui/QtGuiContext.cxx b/src/genericgui/QtGuiContext.cxx index 107c8fe99..4722ea1cc 100644 --- a/src/genericgui/QtGuiContext.cxx +++ b/src/genericgui/QtGuiContext.cxx @@ -73,6 +73,9 @@ QtGuiContext::~QtGuiContext() _current = 0; _QtCurrent = 0; _setOfContext.erase(this); + // Avoid any possible copy from the destroyed schema. + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setMimeData(NULL); } void QtGuiContext::setProc(YACS::ENGINE::Proc* proc) diff --git a/src/hmi/guiObservers.cxx b/src/hmi/guiObservers.cxx index bef6448a1..ec0d6bd2d 100644 --- a/src/hmi/guiObservers.cxx +++ b/src/hmi/guiObservers.cxx @@ -824,6 +824,12 @@ bool SubjectNode::copy(Subject* parent) YASSERT(cnp); Proc *proc = GuiContext::getCurrent()->getProc(); Proc *fromproc=_node->getProc(); + if(proc != fromproc) + { + GuiContext::getCurrent()->_lastErrorMessage = "It is not possible to paste an object from one schema to another."; + DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage); + return false; + } string position = ""; if (fromproc != dynamic_cast(_node)) -- 2.39.2