Issue 0020572: EDF 1150 OCC: SIGSEGV when Salome is closing after execution of a GEOM script

This commit is contained in:
vsr 2009-11-04 11:54:31 +00:00
parent 418a6b7ea1
commit 9695d3c057
5 changed files with 61 additions and 43 deletions

View File

@ -203,17 +203,19 @@ GEOM_Engine::~GEOM_Engine()
* GetDocument * GetDocument
*/ */
//============================================================================= //=============================================================================
Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID) Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID, bool force)
{ {
Handle(TDocStd_Document) aDoc; 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); _OCAFApp->NewDocument("SALOME_GEOM", aDoc);
aDoc->SetUndoLimit(_UndoLimit); aDoc->SetUndoLimit(_UndoLimit);
_mapIDDocument.Bind(theDocID, aDoc); _mapIDDocument.Bind(theDocID, aDoc);
TDataStd_Integer::Set(aDoc->Main(), theDocID); TDataStd_Integer::Set(aDoc->Main(), theDocID);
} }
return aDoc;
return Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
} }
//============================================================================= //=============================================================================
@ -236,17 +238,24 @@ int GEOM_Engine::GetDocID(Handle(TDocStd_Document) theDocument)
* GetObject * GetObject
*/ */
//============================================================================= //=============================================================================
Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry) Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry, bool force)
{ {
Handle(GEOM_Object) anObject;
TCollection_AsciiString anID = BuildID(theDocID, theEntry); TCollection_AsciiString anID = BuildID(theDocID, theEntry);
if(_objects.IsBound(anID)) return Handle(GEOM_Object)::DownCast(_objects(anID));
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_Label aLabel;
Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True); TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True);
Handle(GEOM_Object) anObject = new GEOM_Object(aLabel); anObject = new GEOM_Object(aLabel);
_objects.Bind(anID, anObject); _objects.Bind(anID, anObject);
}
}
return anObject; return anObject;
} }
@ -390,6 +399,8 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject)
if (theObject.IsNull()) return false; if (theObject.IsNull()) return false;
int aDocID = theObject->GetDocID(); int aDocID = theObject->GetDocID();
if(!_mapIDDocument.IsBound(aDocID))
return false; // document is closed...
//Remove an object from the map of available objects //Remove an object from the map of available objects
TCollection_AsciiString anID = BuildIDFromObject(theObject); TCollection_AsciiString anID = BuildIDFromObject(theObject);

View File

@ -82,7 +82,7 @@ class GEOM_Engine
Standard_EXPORT static GEOM_Engine* GetEngine(); Standard_EXPORT static GEOM_Engine* GetEngine();
//Returns the OCAF document by its ID, if document doesn't exists it will be created //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 //Returns the ID of the given OCAF document
Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument); Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument);
@ -91,7 +91,7 @@ class GEOM_Engine
Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; } Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; }
//Returns a pointer to GEOM_Object defined by a document and the entry //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 //Adds a new object of the type theType in the OCAF document
Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType); Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType);

View File

@ -147,8 +147,14 @@ Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel)
*/ */
//============================================================================= //=============================================================================
GEOM_Object::GEOM_Object(TDF_Label& theEntry) 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)) if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root))
_root = TDataStd_TreeNode::Set(theEntry); _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) 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); theEntry.ForgetAllAttributes(Standard_True);
if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root)) if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root))
@ -262,13 +274,7 @@ void GEOM_Object::IncrementTic()
//============================================================================= //=============================================================================
int GEOM_Object::GetDocID() int GEOM_Object::GetDocID()
{ {
Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); return _docID;
if(aDoc.IsNull()) return -1;
Handle(TDataStd_Integer) anID;
if(!aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) return -1;
return anID->Get();
} }

View File

@ -300,6 +300,7 @@ class GEOM_Object : public MMgt_TShared
TDF_Label _label; TDF_Label _label;
TCollection_AsciiString _ior; TCollection_AsciiString _ior;
TCollection_AsciiString _parameters; TCollection_AsciiString _parameters;
int _docID;
}; };
#endif #endif

View File

@ -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) void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
{ {
CORBA::String_var anEntry = theObject->GetEntry(); 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; if (anObject.IsNull()) return;
_impl->RemoveObject(anObject); _impl->RemoveObject(anObject);
return; return;
@ -1808,8 +1808,10 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
//===================================================================================== //=====================================================================================
extern "C" extern "C"
{ {
/*
GEOM_I_EXPORT GEOM_I_EXPORT
PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*); PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
*/
GEOM_I_EXPORT GEOM_I_EXPORT
PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb, PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
@ -1819,8 +1821,6 @@ GEOM_I_EXPORT
const char* interfaceName) const char* interfaceName)
{ {
GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, 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(); return myGEOM_Gen_i->getId();
} }
} }