From 83cf726cd611e421af9d590768f8af8f55d52791 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 31 Oct 2017 18:37:44 -0400 Subject: [PATCH] Fix crash when no symbol libraries are found. Remove adding the power symbol library when no libraries are specified in the project file to prevent unexpected missing library dialog. Only show progress dialog if there are actually libraries to load. Do not call wxWindow::Destroy(). The dialog is created on the stack and will be destroyed properly in the wxWindow dtor. Fixes lp:1728648 https://bugs.launchpad.net/kicad/+bug/1728648 --- eeschema/class_library.cpp | 123 +++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index efdfd85a09..1e0fe974a1 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -546,6 +546,7 @@ const wxString PART_LIBS::CacheName( const wxString& aFullProjectFilename ) return new_name.GetFullPath(); } } + return wxEmptyString; } @@ -564,82 +565,74 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) LibNamesAndPaths( aProject, false, NULL, &lib_names ); - // If the list is empty, force loading the standard power symbol library. - if( !lib_names.GetCount() ) - lib_names.Add( "power" ); - - wxASSERT( !size() ); // expect to load into "this" empty container. - - wxProgressDialog lib_dialog( _( "Loading Symbol Libraries" ), - wxEmptyString, - lib_names.GetCount(), - NULL, - wxPD_APP_MODAL ); - - if( aShowProgress ) + if( !lib_names.empty() ) { - lib_dialog.Show(); - } + wxProgressDialog lib_dialog( _( "Loading Symbol Libraries" ), + wxEmptyString, + lib_names.GetCount(), + NULL, + wxPD_APP_MODAL ); - wxString progress_message; - - for( unsigned i = 0; i < lib_names.GetCount(); ++i ) - { if( aShowProgress ) { - lib_dialog.Update( i, _( "Loading " + lib_names[i] ) ); + lib_dialog.Show(); } - // lib_names[] does not store the file extension. Set it. - // Remember lib_names[i] can contain a '.' in name, so using a wxFileName - // before adding the extension can create incorrect full filename - wxString fullname = lib_names[i] + "." + SchematicLibraryFileExtension; - // Now the full name is set, we can use a wxFileName. - wxFileName fn( fullname ); + wxString progress_message; - // Skip if the file name is not valid.. - if( !fn.IsOk() ) - continue; - - if( !fn.FileExists() ) + for( unsigned i = 0; i < lib_names.GetCount(); ++i ) { - filename = lib_search->FindValidPath( fn.GetFullPath() ); - - if( !filename ) + if( aShowProgress ) { - libs_not_found += fn.GetFullPath(); - libs_not_found += '\n'; + lib_dialog.Update( i, _( "Loading " + lib_names[i] ) ); + } + + // lib_names[] does not store the file extension. Set it. + // Remember lib_names[i] can contain a '.' in name, so using a wxFileName + // before adding the extension can create incorrect full filename + wxString fullname = lib_names[i] + "." + SchematicLibraryFileExtension; + // Now the full name is set, we can use a wxFileName. + wxFileName fn( fullname ); + + // Skip if the file name is not valid.. + if( !fn.IsOk() ) continue; + + if( !fn.FileExists() ) + { + filename = lib_search->FindValidPath( fn.GetFullPath() ); + + if( !filename ) + { + libs_not_found += fn.GetFullPath(); + libs_not_found += '\n'; + continue; + } + } + else + { // ensure the lib filename has a absolute path. + // If the lib has no absolute path, and is found in the cwd by fn.FileExists(), + // make a full absolute path, to avoid issues with load library functions which + // expects an absolute path. + if( !fn.IsAbsolute() ) + fn.MakeAbsolute(); + + filename = fn.GetFullPath(); + } + + try + { + AddLibrary( filename ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg; + msg.Printf( _( "Part library '%s' failed to load. Error:\n %s" ), + GetChars( filename ), GetChars( ioe.What() ) ); + + wxLogError( msg ); } } - else - { // ensure the lib filename has a absolute path. - // If the lib has no absolute path, and is found in the cwd by fn.FileExists(), - // make a full absolute path, to avoid issues with load library functions which - // expects an absolute path. - if( !fn.IsAbsolute() ) - fn.MakeAbsolute(); - - filename = fn.GetFullPath(); - } - - try - { - AddLibrary( filename ); - } - catch( const IO_ERROR& ioe ) - { - wxString msg; - msg.Printf( _( "Part library '%s' failed to load. Error:\n %s" ), - GetChars( filename ), GetChars( ioe.What() ) ); - - wxLogError( msg ); - } - } - - if( aShowProgress ) - { - lib_dialog.Destroy(); } // add the special cache library. @@ -672,7 +665,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) { // Use a different exception type so catch()er can route to proper use // of the HTML_MESSAGE_BOX. - THROW_PARSE_ERROR( wxEmptyString, __func__, TO_UTF8(libs_not_found), 0, 0 ); + THROW_PARSE_ERROR( wxEmptyString, __func__, TO_UTF8( libs_not_found ), 0, 0 ); } #if defined(DEBUG) && 1