From: eap Date: Fri, 18 May 2007 10:00:28 +0000 (+0000) Subject: PAL14921 (memory limitation and Salome freeze) X-Git-Tag: V3_2_7~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ee622f5eff5bcac561ced4c8c6faf8f13d0d7d0;p=modules%2Fsmesh.git PAL14921 (memory limitation and Salome freeze) clean submesh if mesh generation breaks due to lack of memory --- diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index 86da9d3a0..53ab8ef2e 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -58,6 +58,21 @@ using namespace std; +//============================================================================= +/*! + * \brief Allocate some memory at construction and release it at destruction. + * Is used to be able to continue working after mesh generation breaks due to + * lack of memory + */ +//============================================================================= + +struct MemoryReserve +{ + char* myBuf; + MemoryReserve(): myBuf( new char[1024*1024*2] ){} + ~MemoryReserve() { delete [] myBuf; } +}; + //============================================================================= /*! * default constructor: @@ -1379,6 +1394,7 @@ bool SMESH_subMesh::ComputeStateEngine(int event) #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif + MemoryReserve aMemoryReserve; algo->InitComputeError(); if ( !_father->HasShapeToMesh() ) // no shape { @@ -1401,18 +1417,22 @@ bool SMESH_subMesh::ComputeStateEngine(int event) _computeError = algo->GetComputeError(); } catch ( std::bad_alloc& exc ) { + printf("std::bad_alloc\n"); if ( _computeError ) { _computeError->myName = COMPERR_MEMORY_PB; //_computeError->myComment = exc.what(); } + cleanSubMesh( this ); throw exc; } catch ( Standard_OutOfMemory& exc ) { + printf("Standard_OutOfMemory\n"); if ( _computeError ) { - _computeError->myName = COMPERR_MEMORY_PB; + _computeError->myName = COMPERR_MEMORY_PB; //_computeError->myComment = exc.what(); } - throw exc; + cleanSubMesh( this ); + throw std::bad_alloc(); } catch (Standard_Failure& exc) { if ( !_computeError ) _computeError = SMESH_ComputeError::New();