Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] Re: (PR#13166) climisc.c:962 assertion failure
Home

[Freeciv-Dev] Re: (PR#13166) climisc.c:962 assertion failure

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: evand@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#13166) climisc.c:962 assertion failure
From: "Jason Dorje Short" <jdorje@xxxxxxxxx>
Date: Tue, 24 May 2005 21:08:34 -0700
Reply-to: bugs@xxxxxxxxxxx

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

evand@xxxxxxxxx wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13166 >
> 
> The following crashes my version freeciv (2.0.1, compiled locally with
> gcc 3.3.5 on Debian Unstable):
> 
> Select a transport you control, with a transported unit you don't control
> Select orders -> unload transporter
> (other player's unit should now be selected)
> Select menu item orders -> go to
> 
> That produces:
> civclient: climisc.c:962: map_get_known: Assertion `pplayer ==
> game.player_ptr' failed.
> Aborted

Good report.  The problem is we're focusing on another player's unit by
mistake in the unload-all command.

This patch should fix it (the second one is for 2.0).  Please test it.

-jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.175
diff -u -r1.175 control.c
--- client/control.c    7 May 2005 05:48:53 -0000       1.175
+++ client/control.c    25 May 2005 04:06:08 -0000
@@ -138,18 +138,24 @@
 }
 
 /**************************************************************************
-note: punit can be NULL
-We make sure that the previous focus unit is refreshed, if necessary,
-_after_ setting the new focus unit (otherwise if the previous unit is
-in a city, the refresh code draws the previous unit instead of the city).
+  Sets the focus unit directly.  The unit given will be given the
+  focus; if NULL the focus will be cleared.
 
- This function can be called directly from packhand.c as a result of
- Wakeup Focus (when a unit goes from Sentried to Idle in the server).
+  This function is called for several reasons.  Sometimes a fast-focus
+  happens immediately as a result of a client action.  Other times it
+  happens because of a server-sent packet that wakes up a unit.
 **************************************************************************/
 void set_unit_focus(struct unit *punit)
 {
   struct unit *punit_old_focus = punit_focus;
 
+  if (punit && punit->owner != game.info.player_idx) {
+    /* Callers should make sure this never happens. */
+    freelog(LOG_ERROR, "Trying to focus on another player's unit!");
+    assert(0);
+    return;
+  }
+
   if (punit != punit_focus) {
     store_focus();
   }
@@ -183,7 +189,8 @@
     }
   }
   
-  /* avoid the old focus unit disappearing: */
+  /* Redraw the old focus unit (to fix blinking or remove the selection
+   * circle). */
   if (punit_old_focus
       && (!punit || !same_pos(punit_old_focus->tile, punit->tile))) {
     refresh_unit_mapcanvas(punit_old_focus, punit_old_focus->tile,
@@ -778,7 +785,9 @@
        request_new_unit_activity(pcargo, ACTIVITY_IDLE);
       }
 
-      plast = pcargo;
+      if (pcargo->owner == game.info.player_idx) {
+       plast = pcargo;
+      }
     }
   } unit_list_iterate_end;
 
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.143.2.12
diff -u -r1.143.2.12 control.c
--- client/control.c    6 Apr 2005 21:24:42 -0000       1.143.2.12
+++ client/control.c    25 May 2005 04:07:17 -0000
@@ -118,6 +118,11 @@
 {
   struct unit *punit_old_focus = punit_focus;
 
+  if (punit && punit->owner != game.player_idx) {
+    freelog(LOG_ERROR, "Trying to focus on another player's unit!");
+    return;
+  }
+
   if (punit != punit_focus) {
     store_focus();
   }
@@ -711,7 +716,9 @@
        request_new_unit_activity(pcargo, ACTIVITY_IDLE);
       }
 
-      plast = pcargo;
+      if (pcargo->owner == game.player_idx) {
+       plast = pcargo;
+      }
     }
   } unit_list_iterate_end;
 

[Prev in Thread] Current Thread [Next in Thread]