Salome HOME
Fix of crash on feature in new part creation
[modules/shaper.git] / src / Model / Model_AttributeReference.cpp
index 43bbabe658fff74259890026c982b1302d55670c..9c51e545b66ee0983cfcb17eb8747ce7dfe96654 100644 (file)
@@ -21,10 +21,13 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
 {
   if(!theObject)
     return;
-  if (!myIsInitialized || value() != theObject) {
-      std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
-          theObject->data());
-      TDF_Label anObjLab = aData->label().Father(); // object label
+  ObjectPtr aValue = value();
+  if (!myIsInitialized || aValue != theObject) {
+    REMOVE_BACK_REF(aValue);
+
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+      theObject->data());
+    TDF_Label anObjLab = aData->label().Father(); // object label
 
     if (owner()->document() == theObject->document()) { // same document, use reference attribute
 
@@ -41,6 +44,9 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
       TDF_Tool::Entry(anObjLab, anEntry);
       TDataStd_AsciiString::Set(myRef->Label(), anEntry);
     }
+    // do it before the transaction finish to make just created/removed objects know dependencies
+    // and reference from composite feature is removed automatically
+    ADD_BACK_REF(theObject);
 
     owner()->data()->sendAttributeUpdated(this);
   }