Pcbnew: use same null check as eeschema for recently used

When Pcbnew's add footprint browser is run up, it constructs
the recently used list without checking for nulls.

Although the DoAddLibrary call does internally check for
null, it's easier to filter these out before placing into
the vector in the first place.

The same logic in the symbol tree is already handled in the
same way.

(cherry picked from commit 42d20cbd96)
This commit is contained in:
John Beard 2019-04-29 16:32:37 +01:00
parent 0ba130dbd3
commit 89d39cf8ff
2 changed files with 9 additions and 5 deletions

View File

@ -145,6 +145,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree(
{
LIB_ALIAS* alias = GetLibAlias( i.LibId );
// This can be null, for example when a symbol has been deleted from a library
if( alias )
history_list.push_back( alias );
}

View File

@ -227,17 +227,20 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect, bool aAll
std::vector<LIB_TREE_ITEM*> historyInfos;
for( auto const& item : s_ModuleHistoryList )
historyInfos.push_back( GFootprintList.GetModuleInfo( item ) );
{
LIB_TREE_ITEM* fp_info = GFootprintList.GetModuleInfo( item );
// this can be null, for example, if the footprint has been deleted from a library.
if( fp_info != nullptr )
historyInfos.push_back( fp_info );
}
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, historyInfos, true );
if( aPreselect.IsValid() )
adapter->SetPreselectNode( aPreselect, 0 );
else if( historyInfos.size() )
{
if( historyInfos[0] ) // Can be null if the footprint was deleted since the last call
adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 );
}
adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 );
adapter->AddLibraries();