Try/catch gerber file loading in attempt to catch oom
Potentially help with #7444
This commit is contained in:
parent
eb343d3f8f
commit
850a22c3ae
|
@ -38,6 +38,7 @@
|
|||
// HTML Messages used more than one time:
|
||||
#define MSG_NO_MORE_LAYER _( "<b>No more available layers</b> in GerbView to load files" )
|
||||
#define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" )
|
||||
#define MSG_OOM _( "\n<b>Memory was exhausted reading:</b> <i>%s</i>" )
|
||||
|
||||
|
||||
void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
|
||||
|
@ -253,7 +254,9 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath,
|
|||
|
||||
visibility[ layer ] = true;
|
||||
|
||||
if( aFileType && (*aFileType)[ii] == 1 )
|
||||
try
|
||||
{
|
||||
if( aFileType && ( *aFileType )[ii] == 1 )
|
||||
{
|
||||
LoadExcellonFiles( filename.GetFullPath() );
|
||||
layer = GetActiveLayer(); // Loading NC drill file changes the active layer
|
||||
|
@ -264,8 +267,8 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath,
|
|||
{
|
||||
//We cannot read a gerber job file as a gerber plot file: skip it
|
||||
wxString txt;
|
||||
txt.Printf(
|
||||
_( "<b>A gerber job file cannot be loaded as a plot file</b> <i>%s</i>" ),
|
||||
txt.Printf( _( "<b>A gerber job file cannot be loaded as a plot file</b> "
|
||||
"<i>%s</i>" ),
|
||||
filename.GetFullName() );
|
||||
success = false;
|
||||
reporter.Report( txt, RPT_SEVERITY_ERROR );
|
||||
|
@ -276,7 +279,7 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath,
|
|||
|
||||
layer = getNextAvailableLayer( layer );
|
||||
|
||||
if( layer == NO_AVAILABLE_LAYERS && ii < aFilenameList.GetCount()-1 )
|
||||
if( layer == NO_AVAILABLE_LAYERS && ii < aFilenameList.GetCount() - 1 )
|
||||
{
|
||||
success = false;
|
||||
reporter.Report( MSG_NO_MORE_LAYER, RPT_SEVERITY_ERROR );
|
||||
|
@ -286,7 +289,8 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath,
|
|||
while( ii < aFilenameList.GetCount() )
|
||||
{
|
||||
filename = aFilenameList[ii++];
|
||||
wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
|
||||
wxString txt =
|
||||
wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
|
||||
reporter.Report( txt, RPT_SEVERITY_ERROR );
|
||||
}
|
||||
break;
|
||||
|
@ -295,6 +299,14 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath,
|
|||
SetActiveLayer( layer, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( const std::bad_alloc& )
|
||||
{
|
||||
wxString txt = wxString::Format( MSG_OOM, filename.GetFullName() );
|
||||
reporter.Report( txt, RPT_SEVERITY_ERROR );
|
||||
success = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( progress )
|
||||
progress->AdvanceProgress();
|
||||
|
|
|
@ -50,20 +50,23 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
|
|||
Erase_Current_DrawLayer( false );
|
||||
}
|
||||
|
||||
gerber = new GERBER_FILE_IMAGE( layer );
|
||||
// use an unique ptr while we load to free on exception properly
|
||||
std::unique_ptr<GERBER_FILE_IMAGE> gerber_uptr = std::make_unique<GERBER_FILE_IMAGE>( layer );
|
||||
|
||||
// Read the gerber file. The image will be added only if it can be read
|
||||
// to avoid broken data.
|
||||
bool success = gerber->LoadGerberFile( GERBER_FullFileName );
|
||||
bool success = gerber_uptr->LoadGerberFile( GERBER_FullFileName );
|
||||
|
||||
if( !success )
|
||||
{
|
||||
delete gerber;
|
||||
gerber_uptr.reset();
|
||||
msg.Printf( _( "File \"%s\" not found" ), GERBER_FullFileName );
|
||||
ShowInfoBarError( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
gerber = gerber_uptr.release();
|
||||
wxASSERT( gerber != nullptr );
|
||||
images->AddGbrImage( gerber, layer );
|
||||
|
||||
// Display errors list
|
||||
|
|
Loading…
Reference in New Issue