From 56e1afb12e6eae0517487931027f582740700ce7 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 6 Oct 2020 16:59:11 -0700 Subject: [PATCH] Unselect items before rescoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iteration on a suggestion from MikoĊ‚aj Wielgus to resolve elusive crashing issue when searching in lib tree in GTK. GTK issues two commands when clearing (BeforeReset() and AfterReset()) BeforeReset() needs to have a valid model and cannot have selection events during its lifetime. On MacOS and MSW, this is a NOP. AfterReset() performs the re-association for GTK, removing the need for the extra associate step. For MacOS and MSW, this is only the Cleared() action. Fixes https://gitlab.com/kicad/code/kicad/issues/5732 Fixes https://gitlab.com/kicad/code/kicad/issues/5891 --- common/lib_tree_model_adapter.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index da4a58e48a..950cb3bdf9 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -194,6 +194,13 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch ) // 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 ); + BeforeReset(); + + // 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(); Freeze(); m_tree.ResetScore(); @@ -214,26 +221,9 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch ) m_tree.UpdateScore( matcher ); } - // 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(); - m_tree.SortNodes(); - Cleared(); + AfterReset(); Thaw(); - - // This was fixed in wxWidgets 3.0.5 and 3.1.3. -#if defined( __WXGTK__ ) && ( (wxVERSION_NUMBER < 030005 ) || \ - ( ( wxVERSION_NUMBER >= 030100 ) && ( wxVERSION_NUMBER < 030103 ) ) ) - // The fastest method to update wxDataViewCtrl is to rebuild from - // scratch by calling Cleared(). Linux requires to reassociate model to - // display data, but Windows will create multiple associations. - // On MacOS, this crashes kicad. See https://gitlab.com/kicad/code/kicad/issues/3666 - // and https://gitlab.com/kicad/code/kicad/issues/3653 - AttachTo( m_widget ); -#endif } LIB_TREE_NODE* bestMatch = ShowResults();