Symbol editor: fix crash when editing new symbol value field.

This also fixes an ASAN accessing deleted memory warning.  See the issue
tracker comments for more information.

Fixes https://gitlab.com/kicad/code/kicad/issues/4471

(cherry picked from commit a16e9ac76a)
This commit is contained in:
Wayne Stambaugh 2020-05-21 16:46:00 -04:00
parent f971e1267b
commit f262e08d40
1 changed files with 9 additions and 2 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -209,6 +209,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch )
{
wxWindowUpdateLocker updateLock( m_widget );
Freeze();
// 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.
@ -216,8 +217,11 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch )
m_widget->UnselectAll();
Cleared();
Thaw();
#ifdef __WXGTK__
// 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.
@ -414,6 +418,9 @@ bool LIB_TREE_MODEL_ADAPTER::IsContainer( wxDataViewItem const& aItem ) const
wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent( wxDataViewItem const& aItem ) const
{
if( m_freeze )
return ToItem( nullptr );
auto node = ToNode( aItem );
auto parent = node ? node->m_Parent : nullptr;