From 1b88d905b14837ac18a6bac7353896120c1bc787 Mon Sep 17 00:00:00 2001 From: Luke Le Moignan Date: Thu, 29 Dec 2022 02:02:03 +0000 Subject: [PATCH] Fix crash when nonexistent string entered when filtering keywords --- src/gui/control/item_list.cpp | 7 ++++--- src/gui/control/keyword_list.cpp | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gui/control/item_list.cpp b/src/gui/control/item_list.cpp index 93f98ff3..4ca36649 100644 --- a/src/gui/control/item_list.cpp +++ b/src/gui/control/item_list.cpp @@ -180,15 +180,16 @@ void ItemList::refreshList(bool refresh_current_only) { // refresh // Note: Freeze/Thaw makes flicker worse long item_count = (long)sorted_list.size(); + if (item_count == 0) { + Refresh(); + } else { SetItemCount(item_count); // (re)select current item findSelectedItemPos(); focusNone(); focusSelectedItem(true); // refresh items - if (item_count == 0) { - Refresh(); - } else { + RefreshItems(0, item_count - 1); } } diff --git a/src/gui/control/keyword_list.cpp b/src/gui/control/keyword_list.cpp index 9ed2cbf7..3ebb1c8a 100644 --- a/src/gui/control/keyword_list.cpp +++ b/src/gui/control/keyword_list.cpp @@ -54,6 +54,7 @@ void KeywordList::onChangeSet() { } void KeywordList::setFilter(const KeywordListFilterP& filter) { + this->filter = filter; refreshList(); } @@ -191,6 +192,8 @@ int KeywordList::usage(const Keyword& kw) const { // ----------------------------------------------------------------------------- : KeywordList : Item text String KeywordList::OnGetItemText (long pos, long col) const { + if (sorted_list.size() == 0) return wxEmptyString; + const Keyword& kw = *getKeyword(pos); switch(col) { case 0: return kw.keyword; @@ -223,6 +226,7 @@ int KeywordList::OnGetItemImage(long pos) const { } wxListItemAttr* KeywordList::OnGetItemAttr(long pos) const { + if (sorted_list.size() == 0) return nullptr; // black for set keywords, grey for game keywords (uneditable) const Keyword& kw = *getKeyword(pos); if (!kw.fixed && kw.valid) return nullptr;