Author: cazfi
Date: Thu Aug 20 00:23:11 2015
New Revision: 29597

URL: http://svn.gna.org/viewcvs/freeciv?rev=29597&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:
    branches/S2_5/client/gui-gtk-2.0/dialogs.c
    branches/S2_5/client/gui-gtk-2.0/gui_main.c
    branches/S2_5/client/gui-gtk-2.0/gui_main.h
    branches/S2_5/client/gui-gtk-3.0/dialogs.c
    branches/S2_5/client/gui-gtk-3.0/gui_main.c
    branches/S2_5/client/gui-gtk-3.0/gui_main.h

Modified: branches/S2_5/client/gui-gtk-2.0/dialogs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/dialogs.c?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/dialogs.c  (original)
+++ branches/S2_5/client/gui-gtk-2.0/dialogs.c  Thu Aug 20 00:23:11 2015
@@ -1536,14 +1536,16 @@
 *****************************************************************/
 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: branches/S2_5/client/gui-gtk-2.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/gui_main.c?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/gui_main.c (original)
+++ branches/S2_5/client/gui-gtk-2.0/gui_main.c Thu Aug 20 00:23:11 2015
@@ -199,6 +199,7 @@
 static guint srv_id, ggz_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);
@@ -1712,7 +1713,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();
@@ -1727,6 +1730,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: branches/S2_5/client/gui-gtk-2.0/gui_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/gui_main.h?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/gui_main.h (original)
+++ branches/S2_5/client/gui-gtk-2.0/gui_main.h Thu Aug 20 00:23:11 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: branches/S2_5/client/gui-gtk-3.0/dialogs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/dialogs.c?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/dialogs.c  (original)
+++ branches/S2_5/client/gui-gtk-3.0/dialogs.c  Thu Aug 20 00:23:11 2015
@@ -1546,14 +1546,16 @@
 *****************************************************************/
 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: branches/S2_5/client/gui-gtk-3.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/gui_main.c?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/gui_main.c (original)
+++ branches/S2_5/client/gui-gtk-3.0/gui_main.c Thu Aug 20 00:23:11 2015
@@ -184,6 +184,7 @@
 static guint srv_id, ggz_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);
@@ -1736,7 +1737,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();
@@ -1751,6 +1754,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: branches/S2_5/client/gui-gtk-3.0/gui_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/gui_main.h?rev=29597&r1=29596&r2=29597&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/gui_main.h (original)
+++ branches/S2_5/client/gui-gtk-3.0/gui_main.h Thu Aug 20 00:23:11 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