From 13b3c4bbb9681a68f761fb305e7940698eed6fb2 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 21 Feb 2020 13:47:31 +0300 Subject: [PATCH] Fix regression of smesh/bugs_13/N3 (Body Fitting) and SIGSEGV at killSalome.py --- src/SMESH/SMESH_Mesh.cxx | 26 ++++++++++------------ src/StdMeshers/StdMeshers_Cartesian_3D.cxx | 19 +++++++++++----- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 77d19984f..cd5e4315c 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -176,10 +176,18 @@ SMESH_Mesh::~SMESH_Mesh() { if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh"); - // avoid usual removal of elements while processing RemoveHypothesis( algo ) event - SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes(); - while ( smIt->more() ) - const_cast( smIt->next() )->Clear(); + if ( _myDocument ) // avoid destructing _myMeshDS from ~SMESH_Gen() + _myDocument->RemoveMesh( _id ); + _myDocument = 0; + + // remove self from studyContext + if ( _gen ) + { + StudyContextStruct * studyContext = _gen->GetStudyContext(); + studyContext->mapMesh.erase( _id ); + } + + _myMeshDS->ClearMesh(); // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study // Notify event listeners at least that something happens @@ -200,16 +208,6 @@ SMESH_Mesh::~SMESH_Mesh() if ( _callUp) delete _callUp; _callUp = 0; - // remove self from studyContext - if ( _gen ) - { - StudyContextStruct * studyContext = _gen->GetStudyContext(); - studyContext->mapMesh.erase( _id ); - } - if ( _myDocument ) - _myDocument->RemoveMesh( _id ); - _myDocument = 0; - if ( _myMeshDS ) { // delete _myMeshDS, in a thread in order not to block closing a study with large meshes #ifndef WIN32 diff --git a/src/StdMeshers/StdMeshers_Cartesian_3D.cxx b/src/StdMeshers/StdMeshers_Cartesian_3D.cxx index ea641c2b1..78059016f 100644 --- a/src/StdMeshers/StdMeshers_Cartesian_3D.cxx +++ b/src/StdMeshers/StdMeshers_Cartesian_3D.cxx @@ -375,6 +375,7 @@ namespace bool _toUseThresholdForInternalFaces; double _sizeThreshold; + vector< TGeomID > _shapeIDs; // returned by Hexahedron::getSolids() SMESH_MesherHelper* _helper; size_t CellIndex( size_t i, size_t j, size_t k ) const @@ -866,7 +867,7 @@ namespace void init( size_t i ); void setIJK( size_t i ); bool compute( const Solid* solid, const IsInternalFlag intFlag ); - vector< TGeomID > getSolids(); + const vector< TGeomID >& getSolids(); bool isCutByInternalFace( IsInternalFlag & maxFlag ); void addEdges(SMESH_MesherHelper& helper, vector< Hexahedron* >& intersectedHex, @@ -2174,8 +2175,14 @@ namespace /*! * \brief Return IDs of SOLIDs interfering with this Hexahedron */ - vector< TGeomID > Hexahedron::getSolids() + const vector< TGeomID >& Hexahedron::getSolids() { + _grid->_shapeIDs.clear(); + if ( _grid->_geometry.IsOneSolid() ) + { + _grid->_shapeIDs.push_back( _grid->GetSolid()->ID() ); + return _grid->_shapeIDs; + } // count intersection points belonging to each SOLID TID2Nb id2NbPoints; id2NbPoints.reserve( 3 ); @@ -2224,12 +2231,12 @@ namespace insertAndIncrement( solidIDs[i], id2NbPoints ); } - vector< TGeomID > solids; solids.reserve( id2NbPoints.size() ); + _grid->_shapeIDs.reserve( id2NbPoints.size() ); for ( TID2Nb::iterator id2nb = id2NbPoints.begin(); id2nb != id2NbPoints.end(); ++id2nb ) if ( id2nb->second >= 3 ) - solids.push_back( id2nb->first ); + _grid->_shapeIDs.push_back( id2nb->first ); - return solids; + return _grid->_shapeIDs; } //================================================================================ @@ -2571,7 +2578,7 @@ namespace solid = _grid->GetSolid(); if ( !_grid->_geometry.IsOneSolid() ) { - vector< TGeomID > solidIDs = getSolids(); + const vector< TGeomID >& solidIDs = getSolids(); if ( solidIDs.size() > 1 ) { for ( size_t i = 0; i < solidIDs.size(); ++i ) -- 2.30.2