Pcbnew: fix a crash due to use of invalid pointers after a list modification

from master branch, fix bug #4409
This commit is contained in:
jean-pierre charras 2020-05-13 14:04:20 +02:00
parent e37e13e700
commit fde7ae4d19
1 changed files with 10 additions and 3 deletions

View File

@ -598,20 +598,27 @@ bool DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow()
m_footprint->Value() = m_texts->at( 1 );
size_t i = 2;
std::vector<TEXTE_MODULE*> items_to_remove;
for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
{
TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
TEXTE_MODULE* textModule = dynamic_cast<TEXTE_MODULE*>( item );
if( textModule )
{
// copy grid table entries till we run out, then delete any remaining texts
if( i < m_texts->size() )
*textModule = m_texts->at( i++ );
else
textModule->DeleteStructure();
else // store this item to remove and delete it later,
// after the graphic list is explored:
items_to_remove.push_back( textModule );
}
}
// Remove items from m_footprint graphic list:
for( TEXTE_MODULE* item: items_to_remove )
item->DeleteStructure();
// if there are still grid table entries, create new texts for them
while( i < m_texts->size() )
{