Avoid MED file reading failure caused by low memory

Failure reason: system(...) command exits with "Cannot allocate memory"
This commit is contained in:
eap 2016-01-29 15:47:48 +03:00
parent 63d763e7b2
commit e074bae4b7
4 changed files with 21 additions and 13 deletions

View File

@ -172,7 +172,7 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
//------------------------------------------------------ //------------------------------------------------------
PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
if (!aNodeInfo) { if (!aNodeInfo) {
aResult = DRS_FAIL; aResult = addMessage("No nodes", /*isFatal=*/true );
continue; continue;
} }
aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
@ -365,9 +365,9 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
} }
#ifndef _DEXCEPT_ #ifndef _DEXCEPT_
} catch(const std::exception& exc) { } catch(const std::exception& exc) {
aResult = DRS_FAIL; aResult = addMessage( exc.what(), /*isFatal=*/true );
} catch (...) { } catch (...) {
aResult = DRS_FAIL; aResult = addMessage( "Unknown exception", /*isFatal=*/true );
} }
#endif #endif
if ( !anElement ) { if ( !anElement ) {
@ -522,10 +522,10 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
#ifndef _DEXCEPT_ #ifndef _DEXCEPT_
}catch(const std::exception& exc){ }catch(const std::exception& exc){
INFOS("Following exception was caught:\n\t"<<exc.what()); INFOS("Following exception was caught:\n\t"<<exc.what());
aResult = DRS_FAIL; aResult = addMessage( exc.what(), /*isFatal=*/true );
}catch(...){ }catch(...){
INFOS("Unknown exception was caught !!!"); INFOS("Unknown exception was caught !!!");
aResult = DRS_FAIL; aResult = addMessage( "Unknown exception", /*isFatal=*/true );
} }
#endif #endif
if(!anIsValidConnect) if(!anIsValidConnect)
@ -958,10 +958,10 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
#ifndef _DEXCEPT_ #ifndef _DEXCEPT_
} catch(const std::exception& exc) { } catch(const std::exception& exc) {
INFOS("The following exception was caught:\n\t"<<exc.what()); INFOS("The following exception was caught:\n\t"<<exc.what());
aResult = DRS_FAIL; aResult = addMessage( exc.what(), /*isFatal=*/true );
} catch(...) { } catch(...) {
INFOS("Unknown exception was caught !!!"); INFOS("Unknown exception was caught !!!");
aResult = DRS_FAIL; aResult = addMessage( "Unknown exception", /*isFatal=*/true );
} }
#endif #endif
if (!anElement) { if (!anElement) {
@ -993,12 +993,12 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
catch(const std::exception& exc) catch(const std::exception& exc)
{ {
INFOS("The following exception was caught:\n\t"<<exc.what()); INFOS("The following exception was caught:\n\t"<<exc.what());
aResult = DRS_FAIL; aResult = addMessage( exc.what(), /*isFatal=*/true );
} }
catch(...) catch(...)
{ {
INFOS("Unknown exception was caught !!!"); INFOS("Unknown exception was caught !!!");
aResult = DRS_FAIL; aResult = addMessage( "Unknown exception", /*isFatal=*/true );
} }
#endif #endif
if (myMesh) if (myMesh)

View File

@ -25,6 +25,7 @@
#include "MED_V2_2_Wrapper.hxx" #include "MED_V2_2_Wrapper.hxx"
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <sstream> #include <sstream>
#include <med.h> #include <med.h>
@ -64,8 +65,9 @@ namespace MED
std::string aCommand = aStr.str(); std::string aCommand = aStr.str();
int aStatus = system(aCommand.c_str()); int aStatus = system(aCommand.c_str());
BEGMSG(MYDEBUG,"aCommand = '"<<aCommand<<"'; aStatus = "<<aStatus<<std::endl); BEGMSG( MYDEBUG,"aCommand = '" << aCommand << "'; aStatus = " << aStatus
if(aStatus != 0) << "; errno = " << errno << " = " << strerror( errno ) << std::endl );
if ( aStatus != 0 && errno != EAGAIN && errno != ENOMEM ) // "Cannot allocate memory" is OK
return aVersion; return aVersion;
} }
#endif #endif

View File

@ -536,6 +536,10 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces()); MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes()); MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
} }
#ifdef _DEBUG_
SMESH_ComputeErrorPtr er = myReader.GetError();
if ( er && !er->IsOK() ) cout << er->myComment << endl;
#endif
// Reading groups (sub-meshes are out of scope of MED import functionality) // Reading groups (sub-meshes are out of scope of MED import functionality)
list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes(); list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();

View File

@ -1424,7 +1424,9 @@ class Mesh:
# Treat compute errors # Treat compute errors
computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom ) computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
shapeText = ""
for err in computeErrors: for err in computeErrors:
if self.mesh.HasShapeToMesh():
shapeText = " on %s" % self.GetSubShapeName( err.subShapeID ) shapeText = " on %s" % self.GetSubShapeName( err.subShapeID )
errText = "" errText = ""
stdErrors = ["OK", #COMPERR_OK stdErrors = ["OK", #COMPERR_OK