Stop some EnsureVisible() calls happening with out-of-range parameters.
authorCarl Hetherington <cth@carlh.net>
Fri, 2 Apr 2021 21:04:27 +0000 (23:04 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Apr 2021 18:48:34 +0000 (20:48 +0200)
src/wx/full_language_tag_dialog.cc
src/wx/language_tag_dialog.cc

index 2b3aeb7debc87f8cbe41d2c4bce7a2a83433d832..a26dcc0bb81a2862ca77a2d612292e6d37effa1f 100644 (file)
@@ -173,7 +173,7 @@ private:
        {
                auto search = _search->GetValue();
                _list->set_search (search.ToStdString());
-               if (search.Length() > 0) {
+               if (search.Length() > 0 && _list->GetItemCount() > 0) {
                        _list->EnsureVisible (0);
                }
                SearchChanged (_search->GetValue().ToStdString());
index c72c64b313c07f0465553d297a5ac0973fe0d816..ca08996c681d01a5d2c47b24ecbfd9000948316b 100644 (file)
@@ -116,7 +116,9 @@ LanguageTagDialog::set (dcp::LanguageTag tag)
                        _custom.push_back (tag);
                        selection = _presets.size() + _custom.size() - 1;
                        populate_list ();
-                       _list->EnsureVisible (_list->GetItemCount() - 1);
+                       if (_list->GetItemCount() > 0) {
+                               _list->EnsureVisible (_list->GetItemCount() - 1);
+                       }
                } else {
                        selection = _presets.size() + std::distance(_custom.begin(), iter);
                }
@@ -125,7 +127,9 @@ LanguageTagDialog::set (dcp::LanguageTag tag)
        }
 
        _list->SetItemState (selection, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
-       _list->EnsureVisible (selection);
+       if (static_cast<int>(selection) < _list->GetItemCount()) {
+               _list->EnsureVisible (selection);
+       }
 }