diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 711ef4595..f486e24c0 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -462,7 +462,12 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject) //Remove an object from the map of available objects TCollection_AsciiString anID = BuildIDFromObject(theObject); - if (_objects.IsBound(anID)) _objects.UnBind(anID); + if (_objects.IsBound(anID)) { + Handle(GEOM_BaseObject) anObject = Handle(GEOM_BaseObject)::DownCast(_objects(anID)); + if ( anObject != theObject ) + anObject->_label = anObject->_label.Root(); + _objects.UnBind(anID); + } // If sub-shape, remove it from the list of sub-shapes of its main shape Handle(GEOM_Object) aGO = Handle(GEOM_Object)::DownCast( theObject ); @@ -491,6 +496,13 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject) if ( aFreeLabels.empty() || aFreeLabels.back() != aLabel ) aFreeLabels.push_back(aLabel); + // we can't explicitely delete theObject. At least prevent its functioning + // as an alive object when aLabel is reused for a new object + theObject->_label = aLabel.Root(); + theObject->_ior.Clear(); + theObject->_parameters.Clear(); + theObject->_docID = -1; + theObject.Nullify(); return true;