0021375: EDF 1671 SMESH: Dump study of current state

avoid crash at deletion of SMESH_subMesh::myOwnListeners at mesh removal

-  std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
+  struct OwnListenerData {
+    ...
+  };
+  std::list< OwnListenerData > myOwnListeners;
This commit is contained in:
eap 2012-02-09 13:11:58 +00:00
parent 14e44c7736
commit 785e19b0ca
2 changed files with 32 additions and 7 deletions

View File

@ -1992,14 +1992,26 @@ SMESH_Hypothesis::Hypothesis_Status
return SMESH_Hypothesis::HYP_OK;
}
//================================================================================
/*!
* \brief Constructor of OwnListenerData
*/
//================================================================================
SMESH_subMesh::OwnListenerData::OwnListenerData( SMESH_subMesh* sm, EventListener* el):
mySubMesh( sm ),
myMeshID( sm ? sm->GetFather()->GetId() : -1 ),
mySubMeshID( sm ? sm->GetId() : -1 ),
myListener( el )
{
}
//================================================================================
/*!
* \brief Sets an event listener and its data to a submesh
* \param listener - the listener to store
* \param data - the listener data to store
* \param where - the submesh to store the listener and it's data
* \param deleteListener - if true then the listener will be deleted as
* it is removed from where submesh
*
* It remembers the submesh where it puts the listener in order to delete
* them when HYP_OK algo_state is lost
@ -2013,7 +2025,7 @@ void SMESH_subMesh::SetEventListener(EventListener* listener,
{
if ( listener && where ) {
where->SetEventListener( listener, data );
myOwnListeners.push_back( make_pair( where, listener ));
myOwnListeners.push_back( OwnListenerData( where, listener ));
}
}
@ -2112,9 +2124,15 @@ void SMESH_subMesh::DeleteEventListener(EventListener* listener)
void SMESH_subMesh::DeleteOwnListeners()
{
list< pair< SMESH_subMesh*, EventListener* > >::iterator sm_l;
for ( sm_l = myOwnListeners.begin(); sm_l != myOwnListeners.end(); ++sm_l)
sm_l->first->DeleteEventListener( sm_l->second );
list< OwnListenerData >::iterator d;
for ( d = myOwnListeners.begin(); d != myOwnListeners.end(); ++d )
{
if ( !_father->MeshExists( d->myMeshID ))
continue;
if ( _father->GetId() == d->myMeshID && !_father->GetSubMeshContaining( d->mySubMeshID ))
continue;
d->mySubMesh->DeleteEventListener( d->myListener );
}
myOwnListeners.clear();
}

View File

@ -153,7 +153,14 @@ protected:
//!< event listeners to notify
std::map< EventListener*, EventListenerData* > myEventListeners;
//!< event listeners to delete when HYP_OK algo_state is lost
std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
struct OwnListenerData {
SMESH_subMesh* mySubMesh;
int myMeshID; // id of mySubMesh->GetFather()
int mySubMeshID;
EventListener* myListener;
OwnListenerData( SMESH_subMesh* sm=0, EventListener* el=0);
};
std::list< OwnListenerData > myOwnListeners;
/*!
* \brief Sets an event listener and its data to a submesh