Pcbnew: fix segfault after deleting a pad from a footprint then performing a DRC action such as a via drag.

This commit is contained in:
Dick Hollenbeck 2015-09-23 19:02:40 -04:00 committed by Wayne Stambaugh
parent 49cad0de95
commit b27176f230
7 changed files with 51 additions and 15 deletions

View File

@ -537,29 +537,27 @@ void MoveMarkedItems( MODULE* module, wxPoint offset )
*/
void DeleteMarkedItems( MODULE* module )
{
BOARD_ITEM* item;
BOARD_ITEM* next_item;
D_PAD* pad;
D_PAD* next_pad;
BOARD* board = module->GetBoard();
if( module == NULL )
return;
pad = module->Pads();
for( ; pad != NULL; pad = next_pad )
for( D_PAD* pad = module->Pads(); pad; pad = next_pad )
{
next_pad = pad->Next();
if( !pad->IsSelected() )
continue;
if( board )
board->PadDelete( pad );
else
pad->DeleteStructure();
}
item = module->GraphicalItems();
for( ; item != NULL; item = next_item )
for( BOARD_ITEM* item = module->GraphicalItems(); item; item = next_item )
{
next_item = item->Next();

View File

@ -1666,6 +1666,14 @@ void BOARD::GetSortedPadListByXthenYCoord( std::vector<D_PAD*>& aVector, int aNe
}
void BOARD::PadDelete( D_PAD* aPad )
{
m_NetInfo.DeletePad( aPad );
aPad->DeleteStructure();
}
TRACK* BOARD::GetTrack( TRACK* aTrace, const wxPoint& aPosition,
LSET aLayerMask ) const
{

View File

@ -1274,6 +1274,14 @@ public:
*/
D_PAD* GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, LSET aLayerMask );
/**
* Function PadDelete
* deletes a given bad from the BOARD by removing it from its module and
* from the m_NetInfo. Makes no UI calls.
* @param aPad is the pad to delete.
*/
void PadDelete( D_PAD* aPad );
/**
* Function GetSortedPadListByXthenYCoord
* first empties then fills the vector with all pads and sorts them by

View File

@ -304,9 +304,8 @@ public:
/**
* Function GetPads
* returns a list of all the pads. The returned list is not
* sorted and contains pointers to PADS, but those pointers do not convey
* ownership of the respective PADs.
* returns a list of all the pads (so long as buildPadsFullList() has
* been recently called). Returned list contains non-owning pointers.
* @return std::vector<D_PAD*>& - a full list of pads
std::vector<D_PAD*>& GetPads()
{
@ -326,6 +325,22 @@ public:
return NULL;
}
bool DeletePad( D_PAD* aPad )
{
std::vector<D_PAD*>::iterator it = m_PadsFullList.begin();
std::vector<D_PAD*>::iterator end = m_PadsFullList.end();
for( ; it != end; ++it )
{
if( *it == aPad )
{
m_PadsFullList.erase( it );
return true;
}
}
return false;
}
///> Constant that holds the "unconnected net" number (typically 0)
///> all items "connected" to this net are actually not connected items
static const int UNCONNECTED;
@ -409,7 +424,7 @@ public:
private:
/**
* Function DeleteData
* Function clear
* deletes the list of nets (and free memory)
*/
void clear();

View File

@ -144,6 +144,7 @@ void NETINFO_LIST::buildListOfNets()
// Add pad to the appropriate list of pads
NETINFO_ITEM* net = pad->GetNet();
// it should not be possible for BOARD_CONNECTED_ITEM to return NULL as a result of GetNet()
wxASSERT( net );
@ -162,6 +163,7 @@ void NETINFO_LIST::buildListOfNets()
m_Parent->SetAreasNetCodesFromNetNames();
}
#if defined(DEBUG)
void NETINFO_LIST::Show() const
{
@ -176,6 +178,7 @@ void NETINFO_LIST::Show() const
}
#endif
void NETINFO_LIST::buildPadsFullList()
{
/*

View File

@ -272,7 +272,9 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
// Compute the min distance to pads
if( testPads )
{
for( unsigned ii = 0; ii<m_pcb->GetPadCount(); ++ii )
unsigned pad_count = m_pcb->GetPadCount();
for( unsigned ii = 0; ii<pad_count; ++ii )
{
D_PAD* pad = m_pcb->GetPad( ii );

View File

@ -220,7 +220,9 @@ void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
EDA_RECT bbox = module->GetBoundingBox();
m_Pcb->m_Status_Pcb = 0;
aPad->DeleteStructure();
GetBoard()->PadDelete( aPad );
// Update the bounding box
module->CalculateBoundingBox();