From d971f7c694877ad87d3ce14c9c754e0b366ca4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Skujenieks?= Date: Fri, 29 Dec 2017 01:33:16 +0200 Subject: [PATCH] Fix segfault in symbol library editor MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.9.1" This is a multi-part message in MIME format. --------------1.9.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit Unselect currently selected item in library tree, before updating library. After update select newly created item. This is needed because update is realized by creating new item and deleting old. The problem was that wxDataViewCtrl selection was also pointer to deleted item. Fixes: lp:1738999 https://bugs.launchpad.net/kicad/+bug/1738999 --- eeschema/libfield.cpp | 7 +++++++ eeschema/widgets/component_tree.cpp | 8 ++++++++ eeschema/widgets/component_tree.h | 5 +++++ 3 files changed, 20 insertions(+) --------------1.9.1 Content-Type: text/x-patch; name="0001-Fix-segfault-in-symbol-library-editor.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-Fix-segfault-in-symbol-library-editor.patch" diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index c4fdb2e..2387e4e 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) @@ -167,7 +169,12 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) m_aliasName = newFieldValue; //m_libMgr->RemovePart( fieldText, lib ); + + // unselect current item + m_treePane->GetCmpTree()->Unselect(); m_libMgr->UpdatePart( parent, lib, fieldText ); + // select new item + m_treePane->GetCmpTree()->SelectLibId( GetCurPart()->GetLibId() ); } diff --git a/eeschema/widgets/component_tree.cpp b/eeschema/widgets/component_tree.cpp index 5452407..562391f 100644 --- a/eeschema/widgets/component_tree.cpp +++ b/eeschema/widgets/component_tree.cpp @@ -157,6 +157,14 @@ void COMPONENT_TREE::Regenerate() setState( m_filtering ? current : m_unfilteredState ); } +void COMPONENT_TREE::Unselect() +{ + auto current_selection = m_tree_ctrl->GetSelection(); + + if( current_selection != nullptr ) + m_tree_ctrl->Unselect( current_selection ); +} + void COMPONENT_TREE::toggleExpand( const wxDataViewItem& aTreeId ) { diff --git a/eeschema/widgets/component_tree.h b/eeschema/widgets/component_tree.h index 1445229..f41a704 100644 --- a/eeschema/widgets/component_tree.h +++ b/eeschema/widgets/component_tree.h @@ -90,6 +90,11 @@ public: * Regenerates the tree. */ void Regenerate(); + + /** + * Unselect currently selected item in wxDataViewCtrl + */ + void Unselect(); protected: /** --------------1.9.1--