Fixed bug in method GetReferncedObject that caused a crash in case if the reference is not valid.

This commit is contained in:
srn 2007-06-14 07:31:16 +00:00
parent 62efaaafaa
commit b48fe17ccb

View File

@ -95,19 +95,31 @@ Handle(GEOM_Object) GEOM_Object::GetObject(TDF_Label& theLabel)
Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel) Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel)
{ {
Handle(TDF_Reference) aRef; Handle(TDF_Reference) aRef;
if (!theLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL; if (!theLabel.FindAttribute(TDF_Reference::GetID(), aRef)) {
return NULL;
}
if(aRef.IsNull() || aRef->Get().IsNull()) {
return NULL;
}
// Get TreeNode of a referenced function // Get TreeNode of a referenced function
Handle(TDataStd_TreeNode) aT, aFather; Handle(TDataStd_TreeNode) aT, aFather;
if (!TDataStd_TreeNode::Find(aRef->Get(), aT)) return NULL; if (!TDataStd_TreeNode::Find(aRef->Get(), aT)) {
return NULL;
}
// Get TreeNode of Object of the referenced function // Get TreeNode of Object of the referenced function
aFather = aT->Father(); aFather = aT->Father();
if (aFather.IsNull()) return NULL; if (aFather.IsNull()) {
return NULL;
}
// Get label of the referenced object // Get label of the referenced object
TDF_Label aLabel = aFather->Label(); TDF_Label aLabel = aFather->Label();
return GEOM_Object::GetObject(aLabel); return GEOM_Object::GetObject(aLabel);
} }
@ -392,8 +404,10 @@ Handle(TColStd_HSequenceOfTransient) GEOM_Object::GetAllDependency()
Standard_Integer aLength = aSeq.Length(); Standard_Integer aLength = aSeq.Length();
if(aLength > 0) { if(aLength > 0) {
anArray = new TColStd_HSequenceOfTransient; anArray = new TColStd_HSequenceOfTransient;
for(Standard_Integer j =1; j<=aLength; j++) for(Standard_Integer j =1; j<=aLength; j++) {
anArray->Append(GetReferencedObject(aSeq(j))); Handle(GEOM_Object) aRefObj = GetReferencedObject(aSeq(j));
if(!aRefObj.IsNull()) anArray->Append(aRefObj);
}
} }
return anArray; return anArray;