From 0533a23185ef7a3f4a3f84c729afa12e4756ca00 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 3 Dec 2020 14:03:43 -0800 Subject: [PATCH] Fix/workaround GTK libtree issue with multi-unit symbols When preparing for clearing the tree, GTK requires walking through parents. After calling "Freeze()" to protect against returning bad data (see #6458 and #4471), we can no longer access Parent() from GTK and the tree cannot be cleared. The fix is to collapse the first element if it is open. This prevents the common case of the history elements being expanded in the tree Fixes https://gitlab.com/kicad/code/kicad/issues/6102 (cherry picked from commit 7eea344f911b10eadaf8069979cfa226e1a296ef) --- common/lib_tree_model_adapter.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index c5251d4384..b2e62fe751 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -190,17 +190,25 @@ void LIB_TREE_MODEL_ADAPTER::DoAddLibrary( wxString const& aNodeName, wxString c void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch ) { { - // DO NOT REMOVE THE FREEZE/THAW. This freeze/thaw is a flag for this model adapter - // that tells it when it shouldn't trust any of the data in the model. When set, it will - // not return invalid data to the UI, since this invalid data can cause crashes. - // This is different than the update locker, which locks the UI aspects only. wxWindowUpdateLocker updateLock( m_widget ); + // This collapse is required before the call to "Freeze()" below. Once Freeze() + // is called, GetParent() will return nullptr. While this works for some calls, it + // segfaults when we have our first library expanded. + // The tree will be expanded again below when we get our matches + if( !aSearch.IsNull() ) + m_widget->Collapse( wxDataViewItem( &*m_tree.m_Children[0] ) ); + // Even with the updateLock, wxWidgets sometimes ties its knickers in // a knot when trying to run a wxdataview_selection_changed_callback() // on a row that has been deleted. // https://bugs.launchpad.net/kicad/+bug/1756255 m_widget->UnselectAll(); + + // DO NOT REMOVE THE FREEZE/THAW. This freeze/thaw is a flag for this model adapter + // that tells it when it shouldn't trust any of the data in the model. When set, it will + // not return invalid data to the UI, since this invalid data can cause crashes. + // This is different than the update locker, which locks the UI aspects only. Freeze(); BeforeReset();