From c40155914809fa6197d95f0c6e79480a7cfb05bb Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 19 Jul 2023 21:16:55 +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-3.22/dialogs.c | 16 +++++++------- client/gui-gtk-4.0/dialogs.c | 16 +++++++------- client/gui-qt/dialogs.cpp | 39 +++++++++++++++++++++++------------ client/gui-sdl2/dialogs.c | 2 +- client/gui-stub/dialogs.c | 2 +- client/include/dialogs_g.h | 6 ++++-- client/tilespec.c | 8 +++---- 7 files changed, 54 insertions(+), 35 deletions(-) diff --git a/client/gui-gtk-3.22/dialogs.c b/client/gui-gtk-3.22/dialogs.c index 2d8975cc65..79a7575718 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -1536,22 +1536,24 @@ 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; if (tset_name != NULL) { - dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, + 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, + 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-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index c18725a0de..fa690df687 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1563,22 +1563,24 @@ 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; if (tset_name != NULL) { - dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, + 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, + 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 9962a204d2..bb733e12b3 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -4326,28 +4326,41 @@ 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 = new QMessageBox(gui()->central_wdg); + if (std_gui != nullptr || fatal) { + char buf[1024]; + QMessageBox *ask = new QMessageBox(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); ask->setWindowTitle(_("Tileset error")); - ask->setAttribute(Qt::WA_DeleteOnClose); - ask->show(); + + if (std_gui != nullptr) { + ask->setAttribute(Qt::WA_DeleteOnClose); + ask->show(); + } else { + ask->exec(); + } } } diff --git a/client/gui-sdl2/dialogs.c b/client/gui-sdl2/dialogs.c index cc3154136a..ab5ef9c9b1 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -3664,7 +3664,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 00545fbab3..93ae7e3704 100644 --- a/client/gui-stub/dialogs.c +++ b/client/gui-stub/dialogs.c @@ -331,7 +331,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 45534b95d2..67be2bc34f 100644 --- a/client/include/dialogs_g.h +++ b/client/include/dialogs_g.h @@ -36,7 +36,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) @@ -81,7 +82,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 e5e8800c31..3326a41f85 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -633,11 +633,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