From 7a76f58950afde4800f771ffe596a56af9a7432b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 28 May 2022 09:47:21 +0300 Subject: [PATCH 44/44] 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 d4178fe631..241e9b65f1 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(struct player *they, struct player *giver, enum clause_type type, int value); -static void popdown_diplomacy_dialog(struct player *they); +static void popdown_diplomacy_dialog(struct diplomacy_dialog *pdialog); static void popdown_diplomacy_dialogs(void); static void popdown_sdip_dialog(void); @@ -135,8 +135,13 @@ void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they) void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they, struct player *initiator) { - popdown_diplomacy_dialog(they); - flush_dirty(); + struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they); + + if (pdialog != NULL) { + dialog_list_remove(dialog_list, pdialog); + popdown_diplomacy_dialog(pdialog); + flush_dirty(); + } } /* ----------------------------------------------------------------------- */ @@ -1219,11 +1224,9 @@ void gui_init_meeting(struct Treaty *ptreaty, struct player *they, /**********************************************************************//** Close diplomacy dialog between client user and given counterpart. **************************************************************************/ -static void popdown_diplomacy_dialog(struct player *they) +static void popdown_diplomacy_dialog(struct diplomacy_dialog *pdialog) { - struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they); - - if (pdialog) { + if (pdialog != NULL) { popdown_window_group_dialog(pdialog->poffers->begin_widget_list, pdialog->poffers->end_widget_list); FC_FREE(pdialog->poffers->scroll); @@ -1237,8 +1240,6 @@ static void popdown_diplomacy_dialog(struct player *they) 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); @@ -1251,8 +1252,10 @@ static void popdown_diplomacy_dialog(struct player *they) static void popdown_diplomacy_dialogs(void) { dialog_list_iterate(dialog_list, pdialog) { - popdown_diplomacy_dialog(pdialog->treaty->plr1); + popdown_diplomacy_dialog(pdialog); } dialog_list_iterate_end; + + dialog_list_clear(dialog_list); } /**********************************************************************//** -- 2.35.1