diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 6c8a9962a7..bc4f8d8d92 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -3519,6 +3519,70 @@ static Standard_Integer OCC31697(Draw_Interpretor& di, Standard_Integer argc, co return 0; } +#include +#include +#include +//======================================================================= +//function : OCC31320 +//purpose : +//======================================================================= +static Standard_Integer OCC31320(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) +{ + if (argc < 3) + { + di << "Usage : " << argv[0] << " DocName ObjName\n"; + return 1; + } + Handle(TObj_Model) aModel; + Handle(TDocStd_Document) D; + if (!DDocStd::GetDocument (argv[1], D)) + { + di << "Error: document " << argv[1] << " not found\n"; + return 1; + } + + TDF_Label aLabel = D->Main(); + Handle(TObj_TModel) aModelAttr; + if (!aLabel.IsNull() && aLabel.FindAttribute (TObj_TModel::GetID(), aModelAttr)) + aModel = aModelAttr->Model(); + + if (aModel.IsNull()) + { + di << "Error: TObj model " << argv[1] << " not found\n"; + return 1; + } + + Handle(TCollection_HExtendedString) aName = new TCollection_HExtendedString (argv[2]); + Handle(TObj_TNameContainer) aDict; + Handle(TObj_Object) anObj = aModel->FindObject (aName, aDict); + + if (aModel.IsNull()) + { + di << "Error: object " << argv[2] << " not found\n"; + return 1; + } + + // do a test: find the first child of an object, remove object and get the father of this child + Handle(TObj_ObjectIterator) aChildrenIter = anObj->GetChildren(); + if (!aChildrenIter->More()) + { + di << "Error: object " << argv[2] << " has no children\n"; + return 1; + } + + Handle(TObj_Object) aChild = aChildrenIter->Value(); + anObj->Detach(); + Handle(TObj_Object) aFather = aChild->GetFatherObject(); + if (!aFather.IsNull()) + { + di << "Error: father is not null\n"; + return 1; + } + + return 0; + +} + void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -3587,5 +3651,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { theCommands.Add("OCC31697", "OCC31697 expression variable", __FILE__, OCC31697, group); + theCommands.Add("OCC31320", "OCC31320 DocName ObjName : tests remove of the children GetFather method if father is removed", __FILE__, OCC31320, group); + return; } diff --git a/src/TKQADraw/EXTERNLIB b/src/TKQADraw/EXTERNLIB index bb588a05a2..816969b002 100755 --- a/src/TKQADraw/EXTERNLIB +++ b/src/TKQADraw/EXTERNLIB @@ -33,6 +33,7 @@ TKXDESTEP TKXSDRAW TKSTL TKXml +TKTObj CSF_gdi32 CSF_advapi32 CSF_user32 diff --git a/src/TObj/TObj_Object.cxx b/src/TObj/TObj_Object.cxx index 2d4dde0b4c..eeef250f94 100644 --- a/src/TObj/TObj_Object.cxx +++ b/src/TObj/TObj_Object.cxx @@ -615,8 +615,12 @@ Standard_Boolean TObj_Object::GetObj(const TDF_Label& theLabel, Handle(TObj_Object) TObj_Object::GetFatherObject (const Handle(Standard_Type)& theType) const { - Handle(TObj_Object) aFather, aSon(this); + Handle(TObj_Object) aFather; + if (myLabel.IsNull()) + return aFather; + + Handle(TObj_Object) aSon(this); while ( aSon->GetObj( aSon->GetLabel().Father(), aFather, Standard_True ) ) { if (theType.IsNull() || aFather->IsKind( theType )) diff --git a/tests/bugs/caf/bug31320 b/tests/bugs/caf/bug31320 new file mode 100644 index 0000000000..ecceec5a39 --- /dev/null +++ b/tests/bugs/caf/bug31320 @@ -0,0 +1,13 @@ +puts "============" +puts "0031320: TObj - method TObj_Object::GetFatherObject() is not protected against deleted object" +puts "============" +puts "" + +pload TOBJ QAcommands + +# create document with object and sub-object +TObjNew TD1 +TObjAddObj TD1 obj +TObjAddChild TD1 obj subobj1 + +OCC31320 TD1 obj