Skip to content

Commit

Permalink
Fix crash when selecting the selected item from a dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 27, 2016
1 parent 296902d commit 6c2e2e9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gui/dialogs/drop_down_list.cpp
Expand Up @@ -33,6 +33,14 @@ REGISTER_DIALOG(drop_down_list)
namespace {
void click_callback(twindow& window, bool&, bool&, tpoint coordinate)
{
// By deselecting any selected row here, we remove the possibility that the click actually deselects the row
// and results in selected_item_ being set to -1.
// It works because this handler is called *before* the listbox's click handler.
tlistbox& list = find_widget<tlistbox>(&window, "list", true);
int sel = list.get_selected_row();
if(sel >= 0) {
list.select_row(sel, false);
}
SDL_Rect rect = window.get_rectangle();
if(coordinate.x < rect.x || coordinate.x > rect.x + rect.w || coordinate.y < rect.y || coordinate.y > rect.y + rect.h ) {
window.set_retval(twindow::CANCEL);
Expand Down

0 comments on commit 6c2e2e9

Please sign in to comment.