diff --git a/src/XCAFDoc/XCAFDoc_DocumentTool.cdl b/src/XCAFDoc/XCAFDoc_DocumentTool.cdl index a73e68b56a..31488faca1 100755 --- a/src/XCAFDoc/XCAFDoc_DocumentTool.cdl +++ b/src/XCAFDoc/XCAFDoc_DocumentTool.cdl @@ -114,4 +114,9 @@ is Paste (me; into : mutable Attribute from TDF; RT : mutable RelocationTable from TDF); + Destroy (me: mutable) is virtual; + ---C++ : alias ~ + ---Purpose: Unregisters the document holding this attribute from an + -- internal global map of XDE documents. + end DocumentTool; diff --git a/src/XCAFDoc/XCAFDoc_DocumentTool.cxx b/src/XCAFDoc/XCAFDoc_DocumentTool.cxx index 0f72b92785..464e53f2af 100755 --- a/src/XCAFDoc/XCAFDoc_DocumentTool.cxx +++ b/src/XCAFDoc/XCAFDoc_DocumentTool.cxx @@ -280,3 +280,23 @@ Standard_Boolean XCAFDoc_DocumentTool::IsXCAFDocument(const Handle(TDocStd_Docu { return RootLDocLMap.IsBound(D->Main().Root()); } + + +//======================================================================= +//function : Destroy +//purpose : Removal of the document from RootLDocLMap is necessary. Otherwise +// there remains orphan labels and upon creation of a new +// label with XCAFDoc_DocumentTool attribute that +// orphan is attempted to get used (when hashes match) causing +// an exception when trying to access its data framework. +//======================================================================= + +void XCAFDoc_DocumentTool::Destroy() +{ + TDF_Label DocL = Label(); + if ( ! DocL.IsNull() ) { + TDF_Label RootL = DocL.Root(); + if ( RootLDocLMap.IsBound( RootL ) ) + RootLDocLMap.UnBind( RootL ); + } +}