From 499eabceb4d10eee2128ffabe7b18682b83ba9bd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 16 May 2017 11:38:00 +0200 Subject: [PATCH] More data validity checks in POINT_EDITOR Fixes: lp:1690658 * https://bugs.launchpad.net/kicad/+bug/1690658 --- pcbnew/tools/point_editor.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 38aba997fc..3e55a20893 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -87,6 +87,9 @@ public: { std::shared_ptr points = std::make_shared( aItem ); + if( !aItem ) + return points; + // Generate list of edit points basing on the item type switch( aItem->Type() ) { @@ -274,12 +277,16 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) view->Add( m_editPoints.get() ); m_editedPoint = NULL; bool modified = false; + bool revert = false; BOARD_COMMIT commit( editFrame ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { + if( revert ) + break; + if( !m_editPoints || evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->UnselectedEvent ) || @@ -336,16 +343,13 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) else if( evt->IsCancel() ) { if( modified ) // Restore the last change - { - commit.Revert(); - updatePoints(); - modified = false; - } + revert = true; // Let the selection tool receive the event too m_toolMgr->PassEvent(); - break; + // Do not exit right now, let the selection clear the selection + //break; } else @@ -356,8 +360,13 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) if( m_editPoints ) { - finishItem(); view->Remove( m_editPoints.get() ); + + if( modified && revert ) + commit.Revert(); + else + finishItem(); + m_editPoints.reset(); } @@ -369,6 +378,9 @@ void POINT_EDITOR::updateItem() const { EDA_ITEM* item = m_editPoints->GetParent(); + if( !item ) + return; + switch( item->Type() ) { case PCB_LINE_T: @@ -529,6 +541,9 @@ void POINT_EDITOR::finishItem() const { EDA_ITEM* item = m_editPoints->GetParent(); + if( !item ) + return; + if( item->Type() == PCB_ZONE_AREA_T ) { ZONE_CONTAINER* zone = static_cast( item ); @@ -549,6 +564,9 @@ void POINT_EDITOR::updatePoints() EDA_ITEM* item = m_editPoints->GetParent(); + if( !item ) + return; + switch( item->Type() ) { case PCB_LINE_T: @@ -887,6 +905,9 @@ int POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent ) EDA_ITEM* item = m_editPoints->GetParent(); + if( !item ) + return 0; + if( item->Type() == PCB_ZONE_AREA_T ) { PCB_BASE_FRAME* frame = getEditFrame();