From c2224ad24c5c209734a40ff74421141135820b50 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 19 Jul 2023 21:58:10 +0300 Subject: [PATCH 22/22] Qt: Fix non-fatal tileset error messages on startup All tileset errors, both fatal and non-fatal, were just crashing the client on startup. Fixed, so that: - Fatal errors show an error dialog before client closes. - Non-fatal won't crash, and error dialogs will be shown when client runs See osdn #47915 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/dialogs.c | 8 +++++--- client/gui-gtk-3.0/dialogs.c | 8 +++++--- client/gui-gtk-3.22/dialogs.c | 8 +++++--- client/gui-qt/dialogs.cpp | 30 +++++++++++++++++++----------- client/gui-sdl2/dialogs.c | 2 +- client/gui-stub/dialogs.c | 2 +- client/include/dialogs_g.h | 6 ++++-- client/tilespec.c | 8 ++++---- 8 files changed, 44 insertions(+), 28 deletions(-) diff --git a/client/gui-gtk-2.0/dialogs.c b/client/gui-gtk-2.0/dialogs.c index 5172ba6c8d..5c1ae4e75b 100644 --- a/client/gui-gtk-2.0/dialogs.c +++ b/client/gui-gtk-2.0/dialogs.c @@ -1516,7 +1516,7 @@ void show_tech_gained_dialog(Tech_type_id tech) Show tileset error dialog. It's blocking as client will shutdown as soon as this function returns. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { if (is_gui_up()) { GtkWidget *dialog; @@ -1525,13 +1525,15 @@ void show_tileset_error(const char *tset_name, const char *msg) dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset \"%s\" problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), tset_name, msg); } else { dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), msg); } diff --git a/client/gui-gtk-3.0/dialogs.c b/client/gui-gtk-3.0/dialogs.c index 628a0e661d..c736dbd65f 100644 --- a/client/gui-gtk-3.0/dialogs.c +++ b/client/gui-gtk-3.0/dialogs.c @@ -1527,7 +1527,7 @@ void show_tech_gained_dialog(Tech_type_id tech) Show tileset error dialog. It's blocking as client will shutdown as soon as this function returns. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { if (is_gui_up()) { GtkWidget *dialog; @@ -1536,13 +1536,15 @@ void show_tileset_error(const char *tset_name, const char *msg) dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset \"%s\" problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), tset_name, msg); } else { dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), msg); } diff --git a/client/gui-gtk-3.22/dialogs.c b/client/gui-gtk-3.22/dialogs.c index f270bacf8f..5d006b02e1 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -1521,7 +1521,7 @@ void show_tech_gained_dialog(Tech_type_id tech) Show tileset error dialog. It's blocking as client will shutdown as soon as this function returns. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { if (is_gui_up()) { GtkWidget *dialog; @@ -1530,13 +1530,15 @@ void show_tileset_error(const char *tset_name, const char *msg) dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset \"%s\" problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), tset_name, msg); } else { dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Tileset problem, " - "it's probably incompatible with the ruleset:\n%s"), + "it's probably incompatible with " + "the ruleset:\n%s"), msg); } diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index dd257d1360..4e71e59a98 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -3489,22 +3489,30 @@ void show_tech_gained_dialog(Tech_type_id tech) /**************************************************************** Show tileset error dialog. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { - char buf[1024]; + QWidget *parent; + fc_client *std_gui = gui(); - if (tset_name != NULL) { - fc_snprintf(buf, sizeof(buf), - _("Tileset \"%s\" problem, it's probably incompatible with the" - " ruleset:\n%s"), tset_name, msg); + if (std_gui != nullptr) { + parent = std_gui->central_wdg; } else { - fc_snprintf(buf, sizeof(buf), - _("Tileset problem, it's probably incompatible with the" - " ruleset:\n%s"), msg); + parent = nullptr; } - if (QCoreApplication::instance() != nullptr) { - QMessageBox ask(gui()->central_wdg); + if (std_gui != nullptr || fatal) { + char buf[1024]; + QMessageBox ask(parent); + + if (tset_name != NULL) { + fc_snprintf(buf, sizeof(buf), + _("Tileset \"%s\" problem, it's probably incompatible with " + "the ruleset:\n%s"), tset_name, msg); + } else { + fc_snprintf(buf, sizeof(buf), + _("Tileset problem, it's probably incompatible with " + "the ruleset:\n%s"), msg); + } ask.setText(buf); ask.setStandardButtons(QMessageBox::Ok); diff --git a/client/gui-sdl2/dialogs.c b/client/gui-sdl2/dialogs.c index a965ed059f..13c54d1700 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -3613,7 +3613,7 @@ void show_tech_gained_dialog(Tech_type_id tech) /**************************************************************** Show tileset error dialog. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { /* PORTME */ } diff --git a/client/gui-stub/dialogs.c b/client/gui-stub/dialogs.c index f9ceb10f22..a52a35d179 100644 --- a/client/gui-stub/dialogs.c +++ b/client/gui-stub/dialogs.c @@ -314,7 +314,7 @@ void show_tech_gained_dialog(Tech_type_id tech) /**************************************************************** Show tileset error dialog. *****************************************************************/ -void show_tileset_error(const char *tset_name, const char *msg) +void show_tileset_error(bool fatal, const char *tset_name, const char *msg) { /* PORTME */ } diff --git a/client/include/dialogs_g.h b/client/include/dialogs_g.h index d5145acf7a..7c1b227fe0 100644 --- a/client/include/dialogs_g.h +++ b/client/include/dialogs_g.h @@ -35,7 +35,8 @@ GUI_FUNC_PROTO(void, popup_notify_goto_dialog, const char *headline, struct tile *ptile) GUI_FUNC_PROTO(void, popup_notify_dialog, const char *caption, const char *headline, const char *lines) -GUI_FUNC_PROTO(void, popup_connect_msg, const char *headline, const char *message) +GUI_FUNC_PROTO(void, popup_connect_msg, + const char *headline, const char *message) GUI_FUNC_PROTO(void, popup_races_dialog, struct player *pplayer) GUI_FUNC_PROTO(void, popdown_races_dialog, void) @@ -79,7 +80,8 @@ GUI_FUNC_PROTO(void, popup_soundset_suggestion_dialog, void) GUI_FUNC_PROTO(void, popup_musicset_suggestion_dialog, void) GUI_FUNC_PROTO(bool, popup_theme_suggestion_dialog, const char *theme_name) GUI_FUNC_PROTO(void, show_tech_gained_dialog, Tech_type_id tech) -GUI_FUNC_PROTO(void, show_tileset_error, const char *tset_name, const char *msg) +GUI_FUNC_PROTO(void, show_tileset_error, + bool fatal, const char *tset_name, const char *msg) GUI_FUNC_PROTO(bool, handmade_scenario_warning, void) GUI_FUNC_PROTO(void, popdown_all_game_dialogs, void) diff --git a/client/tilespec.c b/client/tilespec.c index 1c3b38c2a2..9797e31022 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -592,11 +592,11 @@ void tileset_error(enum log_level level, const char *tset_name, log_base(level, "%s", buf); if (level <= LOG_NORMAL) { - show_tileset_error(tset_name, buf); - } + show_tileset_error(level == LOG_FATAL, tset_name, buf); - if (level == LOG_FATAL) { - exit(EXIT_FAILURE); + if (level == LOG_FATAL) { + exit(EXIT_FAILURE); + } } } -- 2.40.1