Re: [Freeciv-Dev] (PR#39850) missing control re-initialization for second game

2007-12-06 Thread William Allen Simpson

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39850 

William Allen Simpson wrote:
 Obviously not a code path that was well tested  Committing immediately,
 and I'd appreciate independent testing, please.
 
Found another recent report and merged them.  Is it now fixed for everybody?



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39850) missing control re-initialization for second game

2007-12-05 Thread William Allen Simpson

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39850 

Not the way I'd planned to spend my Wednesday evening, but here's the
minimal backport from S2_2 to S2_1 that fixes the crash.  In addition, it
should handle all the other potential bugs reported on this ticket
concerning leaving and starting another game (without quitting the client).
Obviously not a code path that was well tested  Committing immediately,
and I'd appreciate independent testing, please.

Committed S2_1 revision 14139.
Committed S2_2 revision 14140.
Committed trunk revision 14141.

Index: client/control.c
===
--- client/control.c(revision 14138)
+++ client/control.c(working copy)
@@ -62,11 +62,11 @@
 
 /* These should be set via set_hover_state() */
 enum cursor_hover_state hover_state = HOVER_NONE;
-struct tile *hover_tile = NULL;
 enum cursor_action_state action_state = CURSOR_ACTION_DEFAULT;
 enum unit_activity connect_activity;
 enum unit_orders goto_last_order; /* Last order for goto */
 
+static struct tile *hover_tile = NULL;
 static struct unit_list *battlegroups[MAX_NUM_BATTLEGROUPS];
 
 /* units involved in current combat */
@@ -89,7 +89,7 @@
 enum quickselect_type qtype);
 
 /**
-  Called only by main() in client/civclient.c.
+  Called only by client_game_init() in client/civclient.c
 **/
 void control_init(void)
 {
@@ -105,10 +105,11 @@
   for (i = 0; i  MAX_NUM_BATTLEGROUPS; i++) {
 battlegroups[i] = unit_list_new();
   }
+  hover_tile = NULL;
 }
 
 /**
-  Called only by client_exit() in client/civclient.c.
+  Called only by client_game_free() in client/civclient.c
 **/
 void control_done(void)
 {
@@ -124,6 +125,7 @@
   for (i = 0; i  MAX_NUM_BATTLEGROUPS; i++) {
 unit_list_free(battlegroups[i]);
   }
+  free_client_goto();
 }
 
 /**
@@ -896,7 +898,7 @@
 enter_goto_state(punits);
 create_line_at_mouse_pos();
 update_unit_info_label(punits);
-handle_mouse_cursor(NULL);
+control_mouse_cursor(NULL);
   } else {
 assert(goto_is_active());
 goto_add_waypoint();
@@ -923,12 +925,17 @@
   and the information gathered from the tile which is under the mouse 
   cursor (ptile).
 **/
-void handle_mouse_cursor(struct tile *ptile)
+void control_mouse_cursor(struct tile *ptile)
 {
   struct unit *punit = NULL;
   struct city *pcity = NULL;
   struct unit_list *active_units = get_units_in_focus();
 
+  if (C_S_RUNNING != client_state()) {
+action_state = CURSOR_ACTION_DEFAULT;
+return;
+  }
+
   if (is_server_busy()) {
 /* Server will not accept any commands. */
 action_state = CURSOR_ACTION_WAIT;
@@ -938,11 +945,14 @@
 
   if (!ptile) {
 if (hover_tile) {
-  /* hover_tile is the tile which is currently under the mouse cursor. */
+  /* hover_tile is the tile that was previously under the mouse cursor. */
   ptile = hover_tile;
 } else {
+  action_state = CURSOR_ACTION_DEFAULT;
   return;
 }
+  } else {
+hover_tile = ptile;
   }
 
   punit = find_visible_unit(ptile);
@@ -991,8 +1001,6 @@
 /* FIXME */
 break;
   };
-
-  update_unit_info_label(active_units);
 }
 
 /**
@@ -1076,7 +1084,7 @@
 enter_goto_state(punits);
 create_line_at_mouse_pos();
 update_unit_info_label(punits);
-handle_mouse_cursor(NULL);
+control_mouse_cursor(NULL);
   } else {
 assert(goto_is_active());
 goto_add_waypoint();
Index: client/gui-gtk-2.0/mapview.c
===
--- client/gui-gtk-2.0/mapview.c(revision 14138)
+++ client/gui-gtk-2.0/mapview.c(working copy)
@@ -178,7 +178,7 @@
 
   gdk_window_set_cursor(root_window,
 fc_cursors[cursor_type][cursor_frame]);
-  handle_mouse_cursor(NULL);
+  control_mouse_cursor(NULL);
   return TRUE;
 }
 
Index: client/gui-gtk-2.0/gui_main.c
===
--- client/gui-gtk-2.0/gui_main.c   (revision 14138)
+++ client/gui-gtk-2.0/gui_main.c   (working copy)
@@ -607,7 +607,6 @@
 static gboolean mouse_scroll_mapcanvas(GtkWidget *w, GdkEventScroll *ev)
 {
   int scroll_x, scroll_y, xstep, ystep;
-  struct tile *ptile = NULL;
 
   if (!can_client_change_view()) {
 return FALSE;
@@ -647,9 +646,7 @@
 maybe_activate_keyboardless_goto(cur_x, cur_y);
   }
 
-  ptile = canvas_pos_to_tile(cur_x, cur_y);
-  handle_mouse_cursor(ptile);
-  hover_tile = ptile;
+