From 8a0ae207320e1fcc7aa80e4b668f471ef887135b Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 8 Apr 2019 13:40:11 +0300 Subject: [PATCH] Fix CRASH after mesh.RemoveGroupWithContents( group_of_other_mesh ) --- src/SMDS/SMDS_ElementFactory.cxx | 3 +++ src/SMESHUtils/SMESH_Offset.cxx | 5 +++-- src/SMESH_I/SMESH_Mesh_i.cxx | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/SMDS/SMDS_ElementFactory.cxx b/src/SMDS/SMDS_ElementFactory.cxx index 41018a0d9..12b0f80b0 100644 --- a/src/SMDS/SMDS_ElementFactory.cxx +++ b/src/SMDS/SMDS_ElementFactory.cxx @@ -239,6 +239,9 @@ int SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID ) void SMDS_ElementFactory::Free( const SMDS_MeshElement* e ) { + if ( e != FindElement( e->GetID() )) + SALOME_Exception("SMDS_ElementFactory::Free(): element of other mesh"); + if ( !myVtkIDs.empty() ) { size_t id = e->GetID() - 1; diff --git a/src/SMESHUtils/SMESH_Offset.cxx b/src/SMESHUtils/SMESH_Offset.cxx index 1b1f5204e..34e3c9d26 100644 --- a/src/SMESHUtils/SMESH_Offset.cxx +++ b/src/SMESHUtils/SMESH_Offset.cxx @@ -2391,8 +2391,9 @@ namespace // if ( !myLinks[i].IsInternal() ) // myLinks[ i ].myFace = cutterFace; // else - myLinks[ i ].ReplaceCoplanar( newEdge ); - myLinks[ i+1 ].ReplaceCoplanar( newEdge ); + myLinks[ i ].ReplaceCoplanar( newEdge ); + if ( myLinks[i].IsInternal() && i+1 < myLinks.size() ) + myLinks[ i+1 ].ReplaceCoplanar( newEdge ); return; } i += myLinks[i].IsInternal(); diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 67daefbd0..c5a4ecd6e 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -1104,6 +1104,10 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup ) if ( !aGroup ) return; + if ( aGroup->GetMeshServant() != this ) + THROW_SALOME_CORBA_EXCEPTION( "RemoveGroup(): group does not belong to this mesh", + SALOME::BAD_PARAM ); + SALOMEDS::SObject_wrap aGroupSO = _gen_i->ObjectToSObject( theGroup ); if ( !aGroupSO->_is_nil() ) { @@ -1138,6 +1142,11 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup if ( theGroup->_is_nil() ) return; + SMESH_GroupBase_i* groupImpl = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup ); + if ( !groupImpl || groupImpl->GetMeshServant() != this ) + THROW_SALOME_CORBA_EXCEPTION( "RemoveGroupWithContents(): group does not belong to this mesh", + SALOME::BAD_PARAM); + vector nodeIds; // to remove nodes becoming free bool isNodal = ( theGroup->GetType() == SMESH::NODE ); if ( !isNodal && !theGroup->IsEmpty() ) -- 2.39.2