From 9c73167ba2dd90cef68f313ffc163f0b244a69cf Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 28 May 2022 10:15:27 +0300 Subject: [PATCH 19/19] sdl2: Avoid removal of diplomacy dialogs inside their iteration See osdn #44687 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/diplodlg.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/client/gui-sdl2/diplodlg.c b/client/gui-sdl2/diplodlg.c index b1c52c7dc0..358f30b222 100644 --- a/client/gui-sdl2/diplodlg.c +++ b/client/gui-sdl2/diplodlg.c @@ -74,7 +74,7 @@ static void update_acceptance_icons(struct diplomacy_dialog *pdialog); static void update_clauses_list(struct diplomacy_dialog *pdialog); static void remove_clause_widget_from_list(int counterpart, int giver, enum clause_type type, int value); -static void popdown_diplomacy_dialog(int counterpart); +static void popdown_diplomacy_dialog(struct diplomacy_dialog *pdialog); static void popdown_diplomacy_dialogs(void); static void popdown_sdip_dialog(void); @@ -137,8 +137,13 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted, **************************************************************************/ void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from) { - popdown_diplomacy_dialog(counterpart); - flush_dirty(); + struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart); + + if (pdialog != NULL) { + dialog_list_remove(dialog_list, pdialog); + popdown_diplomacy_dialog(pdialog); + flush_dirty(); + } } /* ----------------------------------------------------------------------- */ @@ -1212,11 +1217,9 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from) /************************************************************************** Close diplomacy dialog between client user and given counterpart. **************************************************************************/ -static void popdown_diplomacy_dialog(int counterpart) +static void popdown_diplomacy_dialog(struct diplomacy_dialog *pdialog) { - struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart); - - if (pdialog) { + if (pdialog != NULL) { popdown_window_group_dialog(pdialog->poffers->pBeginWidgetList, pdialog->poffers->pEndWidgetList); FC_FREE(pdialog->poffers->pScroll); @@ -1230,8 +1233,6 @@ static void popdown_diplomacy_dialog(int counterpart) popdown_window_group_dialog(pdialog->pdialog->pBeginWidgetList, pdialog->pdialog->pEndWidgetList); - dialog_list_remove(dialog_list, pdialog); - FC_FREE(pdialog->pdialog->pScroll); FC_FREE(pdialog->pdialog); FC_FREE(pdialog); @@ -1244,8 +1245,10 @@ static void popdown_diplomacy_dialog(int counterpart) static void popdown_diplomacy_dialogs(void) { dialog_list_iterate(dialog_list, pdialog) { - popdown_diplomacy_dialog(player_number(pdialog->treaty.plr1)); + popdown_diplomacy_dialog(pdialog); } dialog_list_iterate_end; + + dialog_list_clear(dialog_list); } /************************************************************************** -- 2.35.1