Fix incorrect management of SCH_SHEET_PIN items when adding or removing them.

Especially new SCH_SHEET_PIN items were added twice, thus creating crashes.

Fixes: lp:1799606
https://bugs.launchpad.net/kicad/+bug/1799606
This commit is contained in:
jean-pierre charras 2018-10-24 16:18:19 +02:00
parent 7d02c11880
commit dc21a60531
3 changed files with 11 additions and 9 deletions

View File

@ -189,9 +189,8 @@ void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
if( aItem->Type() == SCH_SHEET_PIN_T ) if( aItem->Type() == SCH_SHEET_PIN_T )
{ {
RemoveFromScreen( aItem ); // This item is attached to its parent hierarchical sheet,
// and is not accessible by the global list directly and cannot be removed from this list.
// This item is attached to a node, and is not accessible by the global list directly.
SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent(); SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
wxT( "Sheet label has invalid parent item." ) ); wxT( "Sheet label has invalid parent item." ) );

View File

@ -645,6 +645,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
return; return;
viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, false ); viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, false );
if( viewlibFrame && !viewlibFrame->Close() ) // Can close modal component viewer? if( viewlibFrame && !viewlibFrame->Close() ) // Can close modal component viewer?
return; return;
} }
@ -1398,13 +1399,16 @@ void SCH_EDIT_FRAME::addCurrentItemToScreen()
SetSheetNumberAndCount(); SetSheetNumberAndCount();
} }
if( !screen->CheckIfOnDrawList( item ) ) // don't want a loop! if( item->Type() != SCH_SHEET_PIN_T ) // for SCH_SHEET_PIN_T: will be added later
AddToScreen( item ); // to the SCH_SHEET parent
{
if( !screen->CheckIfOnDrawList( item ) ) // don't want a loop!
AddToScreen( item );
}
if( undoItem == item ) if( undoItem == item )
{ {
SetRepeatItem( item ); SetRepeatItem( item );
SaveCopyInUndoList( undoItem, UR_NEW ); SaveCopyInUndoList( undoItem, UR_NEW );
} }
else else
@ -1414,7 +1418,7 @@ void SCH_EDIT_FRAME::addCurrentItemToScreen()
// currently: sheet pin or component field. // currently: sheet pin or component field.
// currently, only a sheet pin can be found as new item, // currently, only a sheet pin can be found as new item,
// because new component fields have a specific handling, and do not appears here // because new component fields have a specific handling, and do not appears here
SaveCopyInUndoList( undoItem, UR_CHANGED ); SaveCopyInUndoList( undoItem, UR_CHANGED ); // Save the parent sheet
if( item->Type() == SCH_SHEET_PIN_T ) if( item->Type() == SCH_SHEET_PIN_T )
( (SCH_SHEET*)undoItem )->AddPin( (SCH_SHEET_PIN*) item ); ( (SCH_SHEET*)undoItem )->AddPin( (SCH_SHEET_PIN*) item );

View File

@ -185,8 +185,6 @@ void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
SetModify(); SetModify();
m_drawList.Remove( aItem );
if( aItem->Type() == SCH_SHEET_PIN_T ) if( aItem->Type() == SCH_SHEET_PIN_T )
{ {
// This structure is attached to a sheet, get the parent sheet object. // This structure is attached to a sheet, get the parent sheet object.
@ -198,6 +196,7 @@ void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
} }
else else
{ {
m_drawList.Remove( aItem );
delete aItem; delete aItem;
} }
} }