Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom.git into Dev_0.7.1
[modules/shaper.git] / src / Model / Model_AttributeReference.cpp
index e65cb91c2e2f6a32cf6537c128c3f62a430992f0..43bbabe658fff74259890026c982b1302d55670c 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModelAPI_AttributeReference.cxx
 // Created:     2 Apr 2014
 // Author:      Mikhail PONIKAROV
@@ -30,8 +32,8 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
         std::dynamic_pointer_cast<Model_Document>(owner()->document());
       myRef->Set(anObjLab);  // references to the object label
        // remove external link attributes (if any)
-      anObjLab.ForgetAttribute(TDataStd_Comment::GetID());
-      anObjLab.ForgetAttribute(TDataStd_AsciiString::GetID());
+      myRef->Label().ForgetAttribute(TDataStd_Comment::GetID());
+      myRef->Label().ForgetAttribute(TDataStd_AsciiString::GetID());
     } else { // different document: store the document name (comment) and entry (string): external
       // if these attributes exist, the link is external: keep reference to access the label
       TDataStd_Comment::Set(myRef->Label(), theObject->document()->id().c_str());
@@ -67,7 +69,9 @@ ObjectPtr Model_AttributeReference::value()
           owner()->document());
       if (aDoc) {
         TDF_Label aRefLab = myRef->Get();
-        return aDoc->object(aRefLab);
+        if (!aRefLab.IsNull()) {  // it may happen with old document, issue #285
+          return aDoc->object(aRefLab);
+        }
       }
     }
   }