From 66c9a87c38b93835db7220a82b7740b21f823ee5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 29 Jul 2022 19:26:35 +0300 Subject: [PATCH 14/14] 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-2.0/gui_main.c | 6 +++-- client/gui-gtk-3.0/gui_main.c | 6 +++-- client/gui-gtk-3.22/gui_main.c | 6 +++-- client/gui-qt/gui_main.cpp | 13 +++++++-- 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 +-- 12 files changed, 72 insertions(+), 35 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 2e5e017af5..8ecc0b10f7 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -316,10 +316,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; @@ -328,6 +350,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 @@ -664,28 +687,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 48ed6ce070..b634734a69 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-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index fbe628e1ef..acd3b96b6e 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -1503,7 +1503,7 @@ void ui_init(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /************************************************************************** @@ -1521,7 +1521,7 @@ static void migrate_options_from_2_5(void) /************************************************************************** Called from client_main(), is what it's named. **************************************************************************/ -void ui_main(int argc, char **argv) +int ui_main(int argc, char **argv) { const gchar *home; guint sig; @@ -1715,6 +1715,8 @@ void ui_main(int argc, char **argv) gtk_widget_destroy(toplevel); message_buffer = NULL; /* Result of destruction of everything */ tileset_free_tiles(tileset); + + return EXIT_SUCCESS; } /************************************************************************** diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index d294cf0d0c..a0051ef0d2 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1634,7 +1634,7 @@ void ui_init(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /************************************************************************** @@ -1707,7 +1707,7 @@ static void migrate_options_from_2_5(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; @@ -1859,6 +1859,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-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 4ba40c9cca..bb36cf0e22 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1667,7 +1667,7 @@ void ui_init(void) **************************************************************************/ int main(int argc, char **argv) { - return client_main(argc, argv); + return client_main(argc, argv, FALSE); } /************************************************************************** @@ -1787,7 +1787,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; @@ -1943,6 +1943,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-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp index c150a363ef..1e930451c4 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -100,7 +100,8 @@ void qtg_ui_init() int main(int argc, char **argv) { setup_gui_funcs(); - return client_main(argc, argv); + + return client_main(argc, argv, TRUE); } /************************************************************************** @@ -168,12 +169,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); @@ -201,6 +208,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 1bb191c91c..f950e547e7 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 502e7bd11a..a647194973 100644 --- a/client/gui-sdl2/gui_main.c +++ b/client/gui-sdl2/gui_main.c @@ -935,7 +935,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); } /************************************************************************** @@ -962,7 +962,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; @@ -1058,6 +1058,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 8abe15b74f..d5838b1a7d 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 b05e0a7777..98916e3afd 100644 --- a/client/gui_interface.c +++ b/client/gui_interface.c @@ -54,9 +54,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 70b67f1bc4..9465045723 100644 --- a/client/gui_interface.h +++ b/client/gui_interface.h @@ -32,7 +32,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