Gerbview: fix crash when reading a .gbrjob, and when a file given by the .gbrjob is not found. A incorrect gerber image was created, creating crash on exit or when enable the layer view.
This commit is contained in:
parent
4e8f191f43
commit
a00caac789
|
@ -247,36 +247,33 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
|
||||||
int layerId = GetActiveLayer(); // current layer used in GerbView
|
int layerId = GetActiveLayer(); // current layer used in GerbView
|
||||||
GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
|
GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
|
||||||
auto gerber_layer = images->GetGbrImage( layerId );
|
auto gerber_layer = images->GetGbrImage( layerId );
|
||||||
auto drill_layer = dynamic_cast<EXCELLON_IMAGE*>( gerber_layer );
|
|
||||||
|
|
||||||
if( gerber_layer && !drill_layer )
|
// OIf the active layer contains old gerber or nc drill data, remove it
|
||||||
{
|
if( gerber_layer )
|
||||||
// The active layer contains old gerber data we have to clear
|
|
||||||
Erase_Current_DrawLayer( false );
|
Erase_Current_DrawLayer( false );
|
||||||
}
|
|
||||||
|
|
||||||
if( drill_layer == nullptr )
|
EXCELLON_IMAGE* drill_layer = new EXCELLON_IMAGE( layerId );
|
||||||
{
|
|
||||||
drill_layer = new EXCELLON_IMAGE( layerId );
|
|
||||||
layerId = images->AddGbrImage( drill_layer, layerId );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( layerId < 0 )
|
|
||||||
{
|
|
||||||
DisplayError( this, _( "No room to load file" ) );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the Excellon drill file:
|
// Read the Excellon drill file:
|
||||||
bool success = drill_layer->LoadFile( aFullFileName );
|
bool success = drill_layer->LoadFile( aFullFileName );
|
||||||
|
|
||||||
if( !success )
|
if( !success )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "File %s not found" ), GetChars( aFullFileName ) );
|
delete drill_layer;
|
||||||
|
msg.Printf( _( "File %s not found" ), aFullFileName );
|
||||||
DisplayError( this, msg );
|
DisplayError( this, msg );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layerId = images->AddGbrImage( drill_layer, layerId );
|
||||||
|
|
||||||
|
if( layerId < 0 )
|
||||||
|
{
|
||||||
|
delete drill_layer;
|
||||||
|
DisplayError( this, _( "No room to load file" ) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Display errors list
|
// Display errors list
|
||||||
if( drill_layer->GetMessages().size() > 0 )
|
if( drill_layer->GetMessages().size() > 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -284,6 +284,24 @@ bool GERBVIEW_FRAME::loadListOfGerberAndDrillFiles( const wxString& aPath,
|
||||||
|
|
||||||
for( unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
|
for( unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
filename = aFilenameList[ii];
|
||||||
|
|
||||||
|
if( !filename.IsAbsolute() )
|
||||||
|
filename.SetPath( aPath );
|
||||||
|
|
||||||
|
// Check for non existing files, to avoid creating broken or useless data
|
||||||
|
// and report all in one error list:
|
||||||
|
if( !filename.FileExists() )
|
||||||
|
{
|
||||||
|
wxString warning;
|
||||||
|
warning << "<b>" << _( "File not found:" ) << "</b><br>"
|
||||||
|
<< filename.GetFullPath() << "<br>";
|
||||||
|
reporter.Report( warning, REPORTER::RPT_WARNING );
|
||||||
|
success = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if( !progress && wxGetUTCTimeMillis() - startTime > progressShowDelay )
|
if( !progress && wxGetUTCTimeMillis() - startTime > progressShowDelay )
|
||||||
{
|
{
|
||||||
progress = std::make_unique<WX_PROGRESS_REPORTER>( this,
|
progress = std::make_unique<WX_PROGRESS_REPORTER>( this,
|
||||||
|
@ -296,11 +314,6 @@ bool GERBVIEW_FRAME::loadListOfGerberAndDrillFiles( const wxString& aPath,
|
||||||
progress->KeepRefreshing();
|
progress->KeepRefreshing();
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = aFilenameList[ii];
|
|
||||||
|
|
||||||
if( !filename.IsAbsolute() )
|
|
||||||
filename.SetPath( aPath );
|
|
||||||
|
|
||||||
m_lastFileName = filename.GetFullPath();
|
m_lastFileName = filename.GetFullPath();
|
||||||
|
|
||||||
SetActiveLayer( layer, false );
|
SetActiveLayer( layer, false );
|
||||||
|
|
|
@ -117,7 +117,7 @@ void GERBER_FILE_IMAGE_LIST::DeleteImage( int aIdx )
|
||||||
GERBER_FILE_IMAGE* gbr_image = GetGbrImage( aIdx );
|
GERBER_FILE_IMAGE* gbr_image = GetGbrImage( aIdx );
|
||||||
|
|
||||||
delete gbr_image;
|
delete gbr_image;
|
||||||
m_GERBER_List[ aIdx ] = NULL;
|
m_GERBER_List[ aIdx ] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a name for image aIdx which can be used in layers manager
|
// Build a name for image aIdx which can be used in layers manager
|
||||||
|
|
|
@ -249,8 +249,8 @@ GERBVIEW_FRAME::~GERBVIEW_FRAME()
|
||||||
|
|
||||||
void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
|
void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
|
||||||
{
|
{
|
||||||
GetGalCanvas()->GetView()->Clear();
|
|
||||||
GetGalCanvas()->StopDrawing();
|
GetGalCanvas()->StopDrawing();
|
||||||
|
GetGalCanvas()->GetView()->Clear();
|
||||||
|
|
||||||
if( m_toolManager )
|
if( m_toolManager )
|
||||||
m_toolManager->DeactivateTool();
|
m_toolManager->DeactivateTool();
|
||||||
|
|
|
@ -51,18 +51,21 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
|
||||||
}
|
}
|
||||||
|
|
||||||
gerber = new GERBER_FILE_IMAGE( layer );
|
gerber = new GERBER_FILE_IMAGE( layer );
|
||||||
images->AddGbrImage( gerber, layer );
|
|
||||||
|
|
||||||
/* Read the gerber file */
|
// 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->LoadGerberFile( GERBER_FullFileName );
|
||||||
|
|
||||||
if( !success )
|
if( !success )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "File \"%s\" not found" ), GetChars( GERBER_FullFileName ) );
|
delete gerber;
|
||||||
|
msg.Printf( _( "File \"%s\" not found" ), GERBER_FullFileName );
|
||||||
DisplayError( this, msg, 10 );
|
DisplayError( this, msg, 10 );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
images->AddGbrImage( gerber, layer );
|
||||||
|
|
||||||
// Display errors list
|
// Display errors list
|
||||||
if( gerber->GetMessages().size() > 0 )
|
if( gerber->GetMessages().size() > 0 )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue