From 4a562f4a0cccc1e19bc5264deadd09c8b3e37724 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 28 May 2022 10:11:41 +0300 Subject: [PATCH 29/29] 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 f9616076a6..0cf7773f3e 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(); + } } /* ----------------------------------------------------------------------- */ @@ -1216,11 +1221,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->begin_widget_list, pdialog->poffers->end_widget_list); FC_FREE(pdialog->poffers->scroll); @@ -1234,8 +1237,6 @@ static void popdown_diplomacy_dialog(int counterpart) popdown_window_group_dialog(pdialog->pdialog->begin_widget_list, pdialog->pdialog->end_widget_list); - dialog_list_remove(dialog_list, pdialog); - FC_FREE(pdialog->pdialog->scroll); FC_FREE(pdialog->pdialog); FC_FREE(pdialog); @@ -1248,8 +1249,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