From 8d68a5ae9a905e1c53eef9bc5f566c37f0c046f6 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 4 May 2011 09:45:11 +0000 Subject: [PATCH] use CheckMemory() to avoid crash due to memory allocation problem --- src/OBJECT/SMESH_Object.cxx | 18 +++++++++--------- src/SMESHGUI/SMESHGUI_ComputeDlg.cxx | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index ded63b793..61b7e3126 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -292,10 +292,10 @@ void SMESH_VisualObjDef::buildNodePrs() { // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, // so check remaining memory size for safety - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 vtkPoints* aPoints = vtkPoints::New(); createPoints( aPoints ); - // SMDS_Mesh::CheckMemory(); + SMDS_Mesh::CheckMemory(); myGrid->SetPoints( aPoints ); aPoints->Delete(); @@ -358,7 +358,7 @@ void SMESH_VisualObjDef::buildElemPrs() // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, // so check remaining memory size for safety - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ]; @@ -384,13 +384,13 @@ void SMESH_VisualObjDef::buildElemPrs() vtkCellArray* aConnectivity = vtkCellArray::New(); aConnectivity->Allocate( aCellsSize, 0 ); - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); aCellTypesArray->SetNumberOfComponents( 1 ); aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 vtkIdList *anIdList = vtkIdList::New(); vtkIdType iElem = 0; @@ -398,7 +398,7 @@ void SMESH_VisualObjDef::buildElemPrs() TConnect aConnect; aConnect.reserve(VTK_CELL_SIZE); - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes { @@ -501,7 +501,7 @@ void SMESH_VisualObjDef::buildElemPrs() iElem++; } } - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 } // Insert cells in grid @@ -510,7 +510,7 @@ void SMESH_VisualObjDef::buildElemPrs() aCellLocationsArray->SetNumberOfComponents( 1 ); aCellLocationsArray->SetNumberOfTuples( aNbCells ); - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 aConnectivity->InitTraversal(); for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) @@ -523,7 +523,7 @@ void SMESH_VisualObjDef::buildElemPrs() aConnectivity->Delete(); anIdList->Delete(); - // SMDS_Mesh::CheckMemory(); // PAL16631 + SMDS_Mesh::CheckMemory(); // PAL16631 } //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx index 5b7fc580f..024660127 100644 --- a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx @@ -821,6 +821,10 @@ void SMESHGUI_BaseComputeOp::computeMesh() memoryLack = true; } + if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes? + memoryLack = true; + } + // NPAL16631: if ( !memoryLack ) { SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0); @@ -830,7 +834,6 @@ void SMESHGUI_BaseComputeOp::computeMesh() // NPAL16631: if ( getSMESHGUI()->automaticUpdate() ) SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() ); long newSize = myMesh->NbElements(); - long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 ); bool limitExceeded; if ( !memoryLack ) { @@ -856,6 +859,7 @@ void SMESHGUI_BaseComputeOp::computeMesh() } else if ( limitExceeded ) { + long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 ); SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) ); -- 2.39.2