From 0e1e6afe3c02ea480153cf3a295d96878b804ac4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 29 Jul 2022 19:11:21 +0300 Subject: [PATCH 48/48] Qt: Postpone initial tileset selection after QApplication creation QImageReader::supportedImageFormats() documentation says that QApplication should be instantiated before calling it. See osdn #43873 Signed-off-by: Marko Lindqvist --- client/client_main.c | 49 +++++++++++++++++++++++----------- client/client_main.h | 3 ++- client/gui-gtk-3.22/gui_main.c | 6 +++-- client/gui-gtk-4.0/gui_main.c | 6 +++-- client/gui-qt/gui_main.cpp | 12 +++++++-- client/gui-qt/qtg_cxxside.h | 2 +- client/gui-sdl2/gui_main.c | 6 +++-- client/gui-stub/gui_main.c | 6 +++-- client/gui_interface.c | 4 +-- client/gui_interface.h | 2 +- client/include/gui_main_g.h | 4 +-- 11 files changed, 67 insertions(+), 33 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index a29443621d..7cc7776499 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -317,10 +317,32 @@ static void client_game_reset(void) link_marks_init(); } +/**********************************************************************//** + Do the initial default tileset selection. +**************************************************************************/ +int default_tileset_select(void) +{ + fill_topo_ts_default(); + + if (forced_tileset_name[0] != '\0') { + if (!tilespec_try_read(forced_tileset_name, TRUE, -1, TRUE)) { + log_error(_("Can't load requested tileset %s!"), forced_tileset_name); + client_exit(EXIT_FAILURE); + return EXIT_FAILURE; + } + } else { + tilespec_try_read(gui_options.default_tileset_name, FALSE, -1, TRUE); + } + + editor_init(); + + return EXIT_SUCCESS; +} + /**********************************************************************//** Entry point for common client code. **************************************************************************/ -int client_main(int argc, char *argv[]) +int client_main(int argc, char *argv[], bool postpone_tileset) { int i; enum log_level loglevel = LOG_NORMAL; @@ -329,6 +351,7 @@ int client_main(int argc, char *argv[]) char *option = NULL; int fatal_assertions = -1; int aii; + int uret; /* Load Windows post-crash debugger */ #ifdef FREECIV_MSWINDOWS @@ -654,28 +677,22 @@ int client_main(int argc, char *argv[]) helpdata_init(); boot_help_texts(); - fill_topo_ts_default(); - - if (forced_tileset_name[0] != '\0') { - if (!tilespec_try_read(forced_tileset_name, TRUE, -1, TRUE)) { - log_error(_("Can't load requested tileset %s!"), forced_tileset_name); - client_exit(EXIT_FAILURE); - return EXIT_FAILURE; - } - } else { - tilespec_try_read(gui_options.default_tileset_name, FALSE, -1, TRUE); - } - audio_real_init(sound_set_name, music_set_name, sound_plugin_name); start_menu_music("music_menu", NULL); - editor_init(); + if (!postpone_tileset) { + int tsret = default_tileset_select(); + + if (tsret != EXIT_SUCCESS) { + return tsret; + } + } /* run gui-specific client */ - ui_main(argc, argv); + uret = ui_main(argc, argv); /* termination */ - client_exit(EXIT_SUCCESS); + client_exit(uret); /* not reached */ return EXIT_SUCCESS; diff --git a/client/client_main.h b/client/client_main.h index 040ef68fca..b30907d89c 100644 --- a/client/client_main.h +++ b/client/client_main.h @@ -48,7 +48,8 @@ enum client_states { C_S_OVER, }; -int client_main(int argc, char *argv[]); +int client_main(int argc, char *argv[], bool postpone_tileset); +int default_tileset_select(void); void client_packet_input(void *packet, int type); diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 9e5e9d7892..59a7805488 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1791,7 +1791,7 @@ void ui_init(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /**********************************************************************//** @@ -1911,7 +1911,7 @@ static void migrate_options_from_gtk3(void) /**********************************************************************//** Called from client_main(), is what it's named. **************************************************************************/ -void ui_main(int argc, char **argv) +int ui_main(int argc, char **argv) { PangoFontDescription *toplevel_font_name; guint sig; @@ -2072,6 +2072,8 @@ void ui_main(int argc, char **argv) menus_free(); message_buffer = NULL; /* Result of destruction of everything */ tileset_free_tiles(tileset); + + return EXIT_SUCCESS; } /**********************************************************************//** diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 8ff5785e44..b4dd95b49e 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1760,7 +1760,7 @@ void ui_init(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /**********************************************************************//** @@ -1931,7 +1931,7 @@ static void migrate_options_from_gtk3_22(void) /**********************************************************************//** Called from client_main(), is what it's named. **************************************************************************/ -void ui_main(int argc, char **argv) +int ui_main(int argc, char **argv) { parse_options(argc, argv); @@ -1972,6 +1972,8 @@ void ui_main(int argc, char **argv) gtk_window_destroy(GTK_WINDOW(toplevel)); message_buffer = NULL; /* Result of destruction of everything */ tileset_free_tiles(tileset); + + return EXIT_SUCCESS; } /**********************************************************************//** diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp index 55a98e38fe..973f452844 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -104,7 +104,7 @@ int main(int argc, char **argv) svg_flag_enable(); #endif // FC_QT_SVGFLAG - return client_main(argc, argv); + return client_main(argc, argv, TRUE); } /**********************************************************************//** @@ -172,12 +172,18 @@ static void migrate_options_from_2_5() The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ -void qtg_ui_main(int argc, char *argv[]) +int qtg_ui_main(int argc, char *argv[]) { if (parse_options(argc, argv)) { qapp = new QApplication(argc, argv); QPixmap *qpm; QIcon app_icon; + int tsret; + + tsret = default_tileset_select(); + if (tsret != EXIT_SUCCESS) { + return tsret; + } tileset_init(tileset); tileset_load_tiles(tileset); @@ -210,6 +216,8 @@ void qtg_ui_main(int argc, char *argv[]) freeciv_qt->fc_main(qapp); } + + return EXIT_SUCCESS; } /**********************************************************************//** diff --git a/client/gui-qt/qtg_cxxside.h b/client/gui-qt/qtg_cxxside.h index 168736123e..c7c502799f 100644 --- a/client/gui-qt/qtg_cxxside.h +++ b/client/gui-qt/qtg_cxxside.h @@ -28,7 +28,7 @@ void setup_gui_funcs(); void qtg_ui_init(); -void qtg_ui_main(int argc, char *argv[]); +int qtg_ui_main(int argc, char *argv[]); void qtg_ui_exit(); enum gui_type qtg_get_gui_type(); diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c index 365a1acd12..981697ed8e 100644 --- a/client/gui-sdl2/gui_main.c +++ b/client/gui-sdl2/gui_main.c @@ -942,7 +942,7 @@ static void clear_double_messages_call(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /**********************************************************************//** @@ -969,7 +969,7 @@ static void migrate_options_from_sdl(void) The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ -void ui_main(int argc, char *argv[]) +int ui_main(int argc, char *argv[]) { SDL_Event __net_user_event; SDL_Event __anim_user_event; @@ -1065,6 +1065,8 @@ void ui_main(int argc, char *argv[]) main_mouse_button_down_handler, main_mouse_button_up_handler, main_mouse_motion_handler); start_quitting(); + + return EXIT_SUCCESS; } /**********************************************************************//** diff --git a/client/gui-stub/gui_main.c b/client/gui-stub/gui_main.c index 32728aedef..c43ea59b24 100644 --- a/client/gui-stub/gui_main.c +++ b/client/gui-stub/gui_main.c @@ -52,7 +52,7 @@ void gui_ui_init(void) int main(int argc, char **argv) { setup_gui_funcs(); - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /**********************************************************************//** @@ -94,7 +94,7 @@ static void parse_options(int argc, char **argv) The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ -void gui_ui_main(int argc, char *argv[]) +int gui_ui_main(int argc, char *argv[]) { parse_options(argc, argv); @@ -104,6 +104,8 @@ void gui_ui_main(int argc, char *argv[]) /* Main loop here */ start_quitting(); + + return EXIT_SUCCESS; } /**********************************************************************//** diff --git a/client/gui_interface.c b/client/gui_interface.c index 76c2e77375..5a979a7820 100644 --- a/client/gui_interface.c +++ b/client/gui_interface.c @@ -55,9 +55,9 @@ void ui_init(void) /**********************************************************************//** Call ui_main callback **************************************************************************/ -void ui_main(int argc, char *argv[]) +int ui_main(int argc, char *argv[]) { - funcs.ui_main(argc, argv); + return funcs.ui_main(argc, argv); } /**********************************************************************//** diff --git a/client/gui_interface.h b/client/gui_interface.h index b59c5412d7..2fad37bf45 100644 --- a/client/gui_interface.h +++ b/client/gui_interface.h @@ -33,7 +33,7 @@ extern "C" { struct gui_funcs { void (*ui_init)(void); - void (*ui_main)(int argc, char *argv[]); + int (*ui_main)(int argc, char *argv[]); void (*ui_exit)(void); enum gui_type (*get_gui_type)(void); diff --git a/client/include/gui_main_g.h b/client/include/gui_main_g.h index 76b9258f24..dae1419838 100644 --- a/client/include/gui_main_g.h +++ b/client/include/gui_main_g.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #include "gui_proto_constructor.h" GUI_FUNC_PROTO(void, ui_init, void) -GUI_FUNC_PROTO(void, ui_main, int argc, char *argv[]) +GUI_FUNC_PROTO(int, ui_main, int argc, char *argv[]) GUI_FUNC_PROTO(void, ui_exit, void) GUI_FUNC_PROTO(void, options_extra_init, void) -- 2.35.1