From fe663d61f64f1e7116438902e18e8779240967e3 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 24 Jan 2012 12:59:44 +0000 Subject: [PATCH] 0021480: EDF 2084 SMESH: SIGSEGV when validating Netgen3D hypothesis In destructor, delete all data and delete mesh DS in a thread --- src/SMESH/SMESH_Mesh.cxx | 51 ++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index aa36feb28..9416618c5 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -66,6 +66,9 @@ #include "Utils_ExceptHandlers.hxx" +#include +#include + using namespace std; // maximum stored group name length in MED file @@ -116,14 +119,29 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId, //================================================================================ SMESH_Mesh::SMESH_Mesh(): - _groupId( 0 ), _nbSubShapes( 0 ) + _id(-1), + _studyId(-1), + _idDoc(-1), + _groupId( 0 ), + _nbSubShapes( 0 ), + _isShapeToMesh( false ), + _myDocument( 0 ), + _myMeshDS( 0 ), + _gen( 0 ), + _isAutoColor( false ), + _isModified( false ), + _shapeDiagonal( 0.0 ), + _rmGroupCallUp( 0 ) { - _myMeshDS = 0; - _isShapeToMesh = false; - _isAutoColor = false; - _isModified = false; - _shapeDiagonal = 0.0; - _rmGroupCallUp = 0; +} + +namespace +{ + void deleteMeshDS(SMESHDS_Mesh* meshDS) + { + //cout << "deleteMeshDS( " << meshDS << endl; + delete meshDS; + } } //============================================================================= @@ -149,8 +167,27 @@ SMESH_Mesh::~SMESH_Mesh() } _mapGroup.clear(); + // delete sub-meshes + map ::iterator sm = _mapSubMesh.begin(); + for ( ; sm != _mapSubMesh.end(); ++sm ) + delete sm->second; + _mapSubMesh.clear(); + if ( _rmGroupCallUp) delete _rmGroupCallUp; _rmGroupCallUp = 0; + + // remove self from studyContext + if ( _gen ) + { + StudyContextStruct * studyContext = _gen->GetStudyContext( _studyId ); + studyContext->mapMesh.erase( _id ); + } + if ( _myDocument ) + _myDocument->RemoveMesh( _id ); + + if ( _myMeshDS ) + // delete _myMeshDS, in a thread in order not to block closing a study with large meshes + boost::thread aThread(boost::bind( & deleteMeshDS, _myMeshDS )); } //=============================================================================