]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Avoid a 'Segmentation violation' when pasting a destroyed object.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 22 Oct 2015 15:18:37 +0000 (17:18 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 22 Oct 2015 15:18:37 +0000 (17:18 +0200)
src/genericgui/GenericGui.cxx
src/genericgui/GuiEditor.cxx
src/genericgui/QtGuiContext.cxx
src/hmi/guiObservers.cxx

index 09f6f813b7e8a9edfda8b58dda7748f54170d955..67d02f5811ad1f851ea797b925ed1e22bb139ae0 100644 (file)
@@ -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");
 }
 
index abf13197cacdd1475b176f95f93ed1af1d3f8079..ecbe765d4cde91e0689ac59f6352d7820d494bbb 100644 (file)
@@ -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()
index 107c8fe995bd0b9eb1a71e702807e6f4cf996aac..4722ea1cc3451c1f2254dc662451847f040cb8ca 100644 (file)
@@ -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)
index bef6448a19fb140725dc0c3a651b5238242d570d..ec0d6bd2d26de47dff397dd234581c564f1fe371 100644 (file)
@@ -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<Proc*>(_node))