Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12152) 2.0.0-beta7: gtk2/win32 crash in appending govs
Home

[Freeciv-Dev] (PR#12152) 2.0.0-beta7: gtk2/win32 crash in appending govs

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: dacas@xxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#12152) 2.0.0-beta7: gtk2/win32 crash in appending govs to menu
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 14:49:25 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12152 >

> [dacas@xxxxxxxxxxxxxxx - Mon Feb 07 12:53:16 2005]:
> 
> Hi,
> 
> I've forgot give the operation system: win xp (prof; sp2).

I can't figure out exactly what the bug is (that place seems ok), but
here is a cleanup patch that adds some extra safeguards.

Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.43.2.13
diff -u -r1.43.2.13 menu.c
--- client/gui-gtk-2.0/menu.c   23 Nov 2004 17:36:56 -0000      1.43.2.13
+++ client/gui-gtk-2.0/menu.c   7 Feb 2005 22:46:03 -0000
@@ -1180,22 +1180,18 @@
     GtkWidget *parent = gtk_item_factory_get_widget(item_factory, path);
 
     if (parent) {
-      int i;
-      GList *list, *iter, *iter_next;
+      GList *list, *iter;
 
       /* remove previous government entries. */
       list = gtk_container_get_children(GTK_CONTAINER(parent));
-      for (iter = g_list_nth(list, 2); iter; iter = iter_next) {
-       iter_next = iter->next;
+      for (iter = g_list_nth(list, 2); iter; iter = g_list_next(iter)) {
        gtk_widget_destroy(GTK_WIDGET(iter->data));
       }
       g_list_free(list);
 
       /* add new government entries. */
-      for (i = 0; i < game.government_count; ++i) {
-        struct government *g = &governments[i];
-
-        if (i != game.government_when_anarchy) {
+      government_iterate(g) {
+        if (g->index != game.government_when_anarchy) {
           GtkWidget *item, *image;
           struct Sprite *gsprite;
          char buf[256];
@@ -1203,24 +1199,23 @@
          my_snprintf(buf, sizeof(buf), _("%s..."), g->name);
           item = gtk_image_menu_item_new_with_label(buf);
 
-          gsprite = get_government(g->index)->sprite;
-          image = gtk_image_new_from_pixmap(gsprite->pixmap, gsprite->mask);
-          gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
-
-          gtk_widget_show(image);
-          gtk_widget_show(item);
+         if ((gsprite = g->sprite)) {
+           image = gtk_image_new_from_pixmap(gsprite->pixmap, gsprite->mask);
+           gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
+           gtk_widget_show(image);
+         }
 
           g_signal_connect(item, "activate",
             G_CALLBACK(government_callback), GINT_TO_POINTER(g->index));
 
-          if (!can_change_to_government(game.player_ptr, i)) {
+          if (!can_change_to_government(game.player_ptr, g->index)) {
             gtk_widget_set_sensitive(item, FALSE);
          }
 
           gtk_menu_shell_append(GTK_MENU_SHELL(parent), item);
           gtk_widget_show(item);
         }
-      }
+      } government_iterate_end;
     }
 
     menus_set_sensitive("<main>/_Reports", TRUE);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12153) PR#12152, Daczi László, 2005/02/07
    • [Freeciv-Dev] (PR#12152) 2.0.0-beta7: gtk2/win32 crash in appending govs to menu, Vasco Alexandre da Silva Costa <=