From 7516c2ed41e1bd2c842ceff33502012672df806b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 19 Jul 2023 21:16:55 +0300 Subject: [PATCH 18/18] 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.0/dialogs.c | 8 ++++--- 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 +++---- 8 files changed, 59 insertions(+), 38 deletions(-) diff --git a/client/gui-gtk-3.0/dialogs.c b/client/gui-gtk-3.0/dialogs.c index 8b3d8b3b28..6e22890f8f 100644 --- a/client/gui-gtk-3.0/dialogs.c +++ b/client/gui-gtk-3.0/dialogs.c @@ -1545,7 +1545,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; @@ -1554,13 +1554,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 2f54472208..947be7f7b8 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -1533,22 +1533,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 0ad6503337..115c3199f1 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1558,22 +1558,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 71e4081199..752edf1c18 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -4219,28 +4219,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 57cdf7bc0a..df7544921e 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -3655,7 +3655,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 078c28e7da..6fc21ae4ab 100644 --- a/client/gui-stub/dialogs.c +++ b/client/gui-stub/dialogs.c @@ -328,7 +328,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 78d523b98a..6997925d30 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) @@ -80,7 +81,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 1a627b0a0a..79a61d9702 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -597,11 +597,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