From ee6060652bb99635494df988ca30cbc62b022bc9 Mon Sep 17 00:00:00 2001 From: Sean Yeh <109418+seanyeh@users.noreply.github.com> Date: Tue, 27 Oct 2020 23:32:09 -0500 Subject: [PATCH] Add bounds checks for unit dismiss and recall --- src/gui/dialogs/unit_recall.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/dialogs/unit_recall.cpp b/src/gui/dialogs/unit_recall.cpp index 98b3d8e372e4..2f603b15e382 100644 --- a/src/gui/dialogs/unit_recall.cpp +++ b/src/gui/dialogs/unit_recall.cpp @@ -313,6 +313,10 @@ void unit_recall::rename_unit(window& window) listbox& list = find_widget(&window, "recall_list", false); const int index = list.get_selected_row(); + if (index == -1) { + return; + } + unit& selected_unit = const_cast(*recall_list_[index].get()); std::string name = selected_unit.name(); @@ -343,6 +347,9 @@ void unit_recall::dismiss_unit(window& window) listbox& list = find_widget(&window, "recall_list", false); const int index = list.get_selected_row(); + if (index == -1) { + return; + } const unit& u = *recall_list_[index].get(); @@ -464,6 +471,11 @@ void unit_recall::filter_text_changed(text_box_base* textbox, const std::string& } list.set_row_shown(show_items); + + // Disable rename and dismiss buttons if no units are shown + const bool any_shown = list.any_rows_shown(); + find_widget