From 8eb22a1e3ef6792bf6aa7d0e8ea80233893c4840 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 28 May 2022 10:15:27 +0300 Subject: [PATCH 9/9] sdl/2: Avoid removal of diplomacy dialogs inside their iteration See osdn #44687 Signed-off-by: Marko Lindqvist --- client/gui-sdl/diplodlg.c | 35 +++++++++++++++++++---------------- client/gui-sdl2/diplodlg.c | 23 +++++++++++++---------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/client/gui-sdl/diplodlg.c b/client/gui-sdl/diplodlg.c index 7c5b32357d..86e8e32855 100644 --- a/client/gui-sdl/diplodlg.c +++ b/client/gui-sdl/diplodlg.c @@ -71,7 +71,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); @@ -134,8 +134,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(); + } } /* ----------------------------------------------------------------------- */ @@ -1207,26 +1212,22 @@ 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); + pdialog->poffers->pEndWidgetList); FC_FREE(pdialog->poffers->pScroll); FC_FREE(pdialog->poffers); - + popdown_window_group_dialog(pdialog->pwants->pBeginWidgetList, - pdialog->pwants->pEndWidgetList); + pdialog->pwants->pEndWidgetList); FC_FREE(pdialog->pwants->pScroll); FC_FREE(pdialog->pwants); - + popdown_window_group_dialog(pdialog->pdialog->pBeginWidgetList, - pdialog->pdialog->pEndWidgetList); - - dialog_list_remove(dialog_list, pdialog); - + pdialog->pdialog->pEndWidgetList); + FC_FREE(pdialog->pdialog->pScroll); FC_FREE(pdialog->pdialog); FC_FREE(pdialog); @@ -1239,8 +1240,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); } /************************************************************************** diff --git a/client/gui-sdl2/diplodlg.c b/client/gui-sdl2/diplodlg.c index d5f24dcaee..825869cd49 100644 --- a/client/gui-sdl2/diplodlg.c +++ b/client/gui-sdl2/diplodlg.c @@ -75,7 +75,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); @@ -138,8 +138,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(); + } } /* ----------------------------------------------------------------------- */ @@ -1213,11 +1218,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); @@ -1231,8 +1234,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); @@ -1245,8 +1246,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