From b48fe17ccb2abdd169af487e771ff2b4676c795d Mon Sep 17 00:00:00 2001 From: srn Date: Thu, 14 Jun 2007 07:31:16 +0000 Subject: [PATCH] Fixed bug in method GetReferncedObject that caused a crash in case if the reference is not valid. --- src/GEOM/GEOM_Object.cxx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index b07b9d390..97c3665cd 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -95,19 +95,31 @@ Handle(GEOM_Object) GEOM_Object::GetObject(TDF_Label& theLabel) Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel) { 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 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 aFather = aT->Father(); - if (aFather.IsNull()) return NULL; + if (aFather.IsNull()) { + return NULL; + } // Get label of the referenced object TDF_Label aLabel = aFather->Label(); - + return GEOM_Object::GetObject(aLabel); } @@ -392,8 +404,10 @@ Handle(TColStd_HSequenceOfTransient) GEOM_Object::GetAllDependency() Standard_Integer aLength = aSeq.Length(); if(aLength > 0) { anArray = new TColStd_HSequenceOfTransient; - for(Standard_Integer j =1; j<=aLength; j++) - anArray->Append(GetReferencedObject(aSeq(j))); + for(Standard_Integer j =1; j<=aLength; j++) { + Handle(GEOM_Object) aRefObj = GetReferencedObject(aSeq(j)); + if(!aRefObj.IsNull()) anArray->Append(aRefObj); + } } return anArray; -- 2.39.2