From 9695d3c057626b847993742e770b376e597e1919 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 4 Nov 2009 11:54:31 +0000 Subject: [PATCH] Issue 0020572: EDF 1150 OCC: SIGSEGV when Salome is closing after execution of a GEOM script --- src/GEOM/GEOM_Engine.cxx | 37 ++++++++++++++++++++++++------------- src/GEOM/GEOM_Engine.hxx | 4 ++-- src/GEOM/GEOM_Object.cxx | 24 +++++++++++++++--------- src/GEOM/GEOM_Object.hxx | 1 + src/GEOM_I/GEOM_Gen_i.cc | 38 +++++++++++++++++++------------------- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 96eed9a93..6911bf932 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -203,17 +203,19 @@ GEOM_Engine::~GEOM_Engine() * GetDocument */ //============================================================================= -Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID) +Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID, bool force) { Handle(TDocStd_Document) aDoc; - if(!_mapIDDocument.IsBound(theDocID)) { + if(_mapIDDocument.IsBound(theDocID)) { + aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID)); + } + else if (force) { _OCAFApp->NewDocument("SALOME_GEOM", aDoc); aDoc->SetUndoLimit(_UndoLimit); _mapIDDocument.Bind(theDocID, aDoc); TDataStd_Integer::Set(aDoc->Main(), theDocID); } - - return Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID)); + return aDoc; } //============================================================================= @@ -236,17 +238,24 @@ int GEOM_Engine::GetDocID(Handle(TDocStd_Document) theDocument) * GetObject */ //============================================================================= -Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry) +Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry, bool force) { - TCollection_AsciiString anID = BuildID(theDocID, theEntry); - if(_objects.IsBound(anID)) return Handle(GEOM_Object)::DownCast(_objects(anID)); + Handle(GEOM_Object) anObject; - TDF_Label aLabel; - Handle(TDocStd_Document) aDoc = GetDocument(theDocID); - TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True); - Handle(GEOM_Object) anObject = new GEOM_Object(aLabel); + TCollection_AsciiString anID = BuildID(theDocID, theEntry); - _objects.Bind(anID, anObject); + if (_objects.IsBound(anID)) { + anObject = Handle(GEOM_Object)::DownCast(_objects(anID)); + } + else if (force) { + Handle(TDocStd_Document) aDoc = GetDocument(theDocID, force); + if ( !aDoc.IsNull()) { + TDF_Label aLabel; + TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True); + anObject = new GEOM_Object(aLabel); + _objects.Bind(anID, anObject); + } + } return anObject; } @@ -390,7 +399,9 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject) if (theObject.IsNull()) return false; int aDocID = theObject->GetDocID(); - + if(!_mapIDDocument.IsBound(aDocID)) + return false; // document is closed... + //Remove an object from the map of available objects TCollection_AsciiString anID = BuildIDFromObject(theObject); if (_objects.IsBound(anID)) _objects.UnBind(anID); diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index 6ec146c92..ae6915284 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -82,7 +82,7 @@ class GEOM_Engine Standard_EXPORT static GEOM_Engine* GetEngine(); //Returns the OCAF document by its ID, if document doesn't exists it will be created - Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID); + Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID, bool force=true); //Returns the ID of the given OCAF document Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument); @@ -91,7 +91,7 @@ class GEOM_Engine Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; } //Returns a pointer to GEOM_Object defined by a document and the entry - Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry); + Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry, bool force=true); //Adds a new object of the type theType in the OCAF document Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType); diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index 38025ab06..dcfd41056 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -147,8 +147,14 @@ Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel) */ //============================================================================= GEOM_Object::GEOM_Object(TDF_Label& theEntry) -: _label(theEntry), _ior("") + : _label(theEntry), _ior(""), _docID(-1) { + Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); + if(!aDoc.IsNull()) { + Handle(TDataStd_Integer) anID; + if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get(); + } + if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root)) _root = TDataStd_TreeNode::Set(theEntry); } @@ -159,8 +165,14 @@ GEOM_Object::GEOM_Object(TDF_Label& theEntry) */ //============================================================================= GEOM_Object::GEOM_Object(TDF_Label& theEntry, int theType) -: _label(theEntry), _ior("") +: _label(theEntry), _ior(""), _docID(-1) { + Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); + if(!aDoc.IsNull()) { + Handle(TDataStd_Integer) anID; + if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get(); + } + theEntry.ForgetAllAttributes(Standard_True); if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root)) @@ -262,13 +274,7 @@ void GEOM_Object::IncrementTic() //============================================================================= int GEOM_Object::GetDocID() { - Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); - if(aDoc.IsNull()) return -1; - - Handle(TDataStd_Integer) anID; - if(!aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) return -1; - - return anID->Get(); + return _docID; } diff --git a/src/GEOM/GEOM_Object.hxx b/src/GEOM/GEOM_Object.hxx index 66f93f642..c79f827e1 100644 --- a/src/GEOM/GEOM_Object.hxx +++ b/src/GEOM/GEOM_Object.hxx @@ -300,6 +300,7 @@ class GEOM_Object : public MMgt_TShared TDF_Label _label; TCollection_AsciiString _ior; TCollection_AsciiString _parameters; + int _docID; }; #endif diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 35d6d742d..58471eebb 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -66,11 +66,11 @@ // function : GEOM_Gen_i() // purpose : constructor to be called for servant creation. //============================================================================ -GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName) : +GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) : Engines_Component_i(orb, poa, contId, instanceName, interfaceName) { _thisObj = this; @@ -1587,7 +1587,7 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject) { CORBA::String_var anEntry = theObject->GetEntry(); - Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry); + Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false); if (anObject.IsNull()) return; _impl->RemoveObject(anObject); return; @@ -1808,19 +1808,19 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) //===================================================================================== extern "C" { -GEOM_I_EXPORT -PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*); - -GEOM_I_EXPORT - PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char * interfaceName) + /* + GEOM_I_EXPORT + PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*); + */ + + GEOM_I_EXPORT + PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) { - GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); - // Don't understand the reason of this register ???? -// myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example - return myGEOM_Gen_i->getId(); + GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); + return myGEOM_Gen_i->getId(); } } -- 2.39.2