Salome HOME
#19232 [CEA] overal Mesh quality crash on imported MED
authoreap <eap@opencascade.com>
Tue, 9 Jun 2020 12:09:07 +0000 (15:09 +0300)
committereap <eap@opencascade.com>
Tue, 9 Jun 2020 12:09:07 +0000 (15:09 +0300)
Bug reason: the med file includes polygons based on none of nodes.
Solution: forbid creating such polygons

src/SMDS/SMDS_Mesh.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx

index a5af798e57899f7806fa9d0f594bbea1a6c9e927..353d0789302b0df8272cc73266a5726446847504 100644 (file)
@@ -831,6 +831,8 @@ SMDS_Mesh::AddPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*> & nod
 {
   if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
 
 {
   if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
 
+  if ( nodes.empty() )
+    throw std::invalid_argument("Polygon without nodes is forbidden");
   if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID ))
   {
     cell->init( SMDSEntity_Polygon, nodes );
   if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID ))
   {
     cell->init( SMDSEntity_Polygon, nodes );
@@ -874,6 +876,8 @@ SMDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*> &
                                        const int                                 ID)
 {
   if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
                                        const int                                 ID)
 {
   if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+  if ( nodes.empty() )
+    throw std::invalid_argument("Polygon without nodes is forbidden");
   if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID ))
   {
     cell->init( SMDSEntity_Quad_Polygon, nodes );
   if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID ))
   {
     cell->init( SMDSEntity_Quad_Polygon, nodes );
index 5ae3c6a6e0cef61d72acfa2773dd632497943ff9..16cc20053d24e05aa276992c8d0193d0c6a23c46 100644 (file)
@@ -1069,6 +1069,12 @@ CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsO
     if ( ! ( nodes[i] = getMeshDS()->FindNode( IDsOfNodes[i] )))
       return 0;
 
     if ( ! ( nodes[i] = getMeshDS()->FindNode( IDsOfNodes[i] )))
       return 0;
 
+  if ( NbNodes == 0 )
+  {
+    INFOS("Polygon without nodes is forbidden");
+    return 0;
+  }
+
   const SMDS_MeshElement* elem = getMeshDS()->AddPolygonalFace(nodes);
 
   // Update Python script
   const SMDS_MeshElement* elem = getMeshDS()->AddPolygonalFace(nodes);
 
   // Update Python script
@@ -1098,6 +1104,12 @@ CORBA::Long SMESH_MeshEditor_i::AddQuadPolygonalFace (const SMESH::long_array &
   for (int i = 0; i < NbNodes; i++)
     nodes[i] = getMeshDS()->FindNode(IDsOfNodes[i]);
 
   for (int i = 0; i < NbNodes; i++)
     nodes[i] = getMeshDS()->FindNode(IDsOfNodes[i]);
 
+  if ( NbNodes == 0 )
+  {
+    INFOS("Polygon without nodes is forbidden");
+    return 0;
+  }
+
   const SMDS_MeshElement* elem = getMeshDS()->AddQuadPolygonalFace(nodes);
 
   // Update Python script
   const SMDS_MeshElement* elem = getMeshDS()->AddQuadPolygonalFace(nodes);
 
   // Update Python script