Author: cazfi
Date: Thu Aug 20 00:22:53 2015
New Revision: 29595

URL: http://svn.gna.org/viewcvs/freeciv?rev=29595&view=rev
Log:
Avoid client crash when it detects problems on some rulesets while constructing 
the list
of valid tilesets, before client gui is set up.

See bug #23794

Modified:
    trunk/client/gui-gtk-2.0/dialogs.c
    trunk/client/gui-gtk-2.0/gui_main.c
    trunk/client/gui-gtk-2.0/gui_main.h
    trunk/client/gui-gtk-3.0/dialogs.c
    trunk/client/gui-gtk-3.0/gui_main.c
    trunk/client/gui-gtk-3.0/gui_main.h

Modified: trunk/client/gui-gtk-2.0/dialogs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/dialogs.c?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/dialogs.c  (original)
+++ trunk/client/gui-gtk-2.0/dialogs.c  Thu Aug 20 00:22:53 2015
@@ -1521,16 +1521,18 @@
 *****************************************************************/
 void show_tileset_error(const char *msg)
 {
-  GtkWidget *dialog;
-
-  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"),
+  if (is_gui_up()) {
+    GtkWidget *dialog;
+
+    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"),
                                     msg);
 
-  gtk_dialog_run(GTK_DIALOG(dialog));
-
-  gtk_widget_destroy(dialog);
+    gtk_dialog_run(GTK_DIALOG(dialog));
+
+    gtk_widget_destroy(dialog);
+  }
 }
 
 /****************************************************************

Modified: trunk/client/gui-gtk-2.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/gui_main.c?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/gui_main.c (original)
+++ trunk/client/gui-gtk-2.0/gui_main.c Thu Aug 20 00:22:53 2015
@@ -193,6 +193,7 @@
 static guint srv_id;
 gint cur_x, cur_y;
 
+static bool gui_up = FALSE;
 
 static gboolean show_info_button_release(GtkWidget *w, GdkEventButton *ev, 
gpointer data);
 static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev, gpointer 
data);
@@ -1678,7 +1679,9 @@
   /* assumes client_state is set */
   timer_id = g_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
 
+  gui_up = TRUE;
   gtk_main();
+  gui_up = FALSE;
 
   destroy_server_scans();
   free_mapcanvas_and_overview();
@@ -1693,6 +1696,14 @@
 }
 
 /**************************************************************************
+  Return whether gui is currently running.
+**************************************************************************/
+bool is_gui_up(void)
+{
+  return gui_up;
+}
+
+/**************************************************************************
   Do any necessary UI-specific cleanup
 **************************************************************************/
 void ui_exit(void)

Modified: trunk/client/gui-gtk-2.0/gui_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/gui_main.h?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/gui_main.h (original)
+++ trunk/client/gui-gtk-2.0/gui_main.h Thu Aug 20 00:22:53 2015
@@ -87,4 +87,6 @@
 void quit_gtk_main(void);
 void refresh_chat_buttons(void);
 
+bool is_gui_up(void);
+
 #endif  /* FC__GUI_MAIN_H */

Modified: trunk/client/gui-gtk-3.0/dialogs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/dialogs.c?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/dialogs.c  (original)
+++ trunk/client/gui-gtk-3.0/dialogs.c  Thu Aug 20 00:22:53 2015
@@ -1531,16 +1531,18 @@
 *****************************************************************/
 void show_tileset_error(const char *msg)
 {
-  GtkWidget *dialog;
-
-  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"),
+  if (is_gui_up()) {
+    GtkWidget *dialog;
+
+    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"),
                                     msg);
 
-  gtk_dialog_run(GTK_DIALOG(dialog));
-
-  gtk_widget_destroy(dialog);
+    gtk_dialog_run(GTK_DIALOG(dialog));
+
+    gtk_widget_destroy(dialog);
+  }
 }
 
 /****************************************************************

Modified: trunk/client/gui-gtk-3.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/gui_main.c?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/gui_main.c (original)
+++ trunk/client/gui-gtk-3.0/gui_main.c Thu Aug 20 00:22:53 2015
@@ -178,6 +178,7 @@
 static guint srv_id;
 gint cur_x, cur_y;
 
+static bool gui_up = FALSE;
 
 static gboolean show_info_button_release(GtkWidget *w, GdkEventButton *ev, 
gpointer data);
 static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev, gpointer 
data);
@@ -1711,7 +1712,9 @@
   /* assumes client_state is set */
   timer_id = g_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
 
+  gui_up = TRUE;
   gtk_main();
+  gui_up = FALSE;
 
   destroy_server_scans();
   free_mapcanvas_and_overview();
@@ -1726,6 +1729,14 @@
 }
 
 /**************************************************************************
+  Return whether gui is currently running.
+**************************************************************************/
+bool is_gui_up(void)
+{
+  return gui_up;
+}
+
+/**************************************************************************
   Do any necessary UI-specific cleanup
 **************************************************************************/
 void ui_exit(void)

Modified: trunk/client/gui-gtk-3.0/gui_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/gui_main.h?rev=29595&r1=29594&r2=29595&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/gui_main.h (original)
+++ trunk/client/gui-gtk-3.0/gui_main.h Thu Aug 20 00:22:53 2015
@@ -78,4 +78,6 @@
 int screen_width(void);
 int screen_height(void);
 
+bool is_gui_up(void);
+
 #endif  /* FC__GUI_MAIN_H */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to