Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] Re: (PR#12256) return of the unit_list_size assert
Home

[Freeciv-Dev] Re: (PR#12256) return of the unit_list_size assert

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12256) return of the unit_list_size assert
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Feb 2005 18:44:00 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=12256 >
> 
> 1: 0x87c4248 Submarine at (56,46) ai2
> civclient: packhand.c:1918: handle_tile_info: Assertion 
> `unit_list_size(ptile->units) == 0' failed.
> Aborted (core dumped)
> 
> I was sub-hunting with a submarine and the client crashed.
> 
> I believe i know why it happens, although it is not easy to reproduce.
> 
> - The enemy sub attacked and sunk one of my cruisers.  The server sends 
> me info about the sub, of course.
> 
> - The death of the cruiser should have put the sub out of sight.  After 
> the cruiser died the sub was out of vision of any of my units, although 
> the tile the sub was on was still within my vision range.
> 
> - When I moved my unit that could see that tile out of range, the tile 
> became fogged.  However the server didn't send a unit_goes_out_of_sight 
> packet because the unit was supposed to already _be_ out of sight.

Here is a savegame and a patch (savegame attached separately).

Load the savegame and connect as jdorje/italians.  Press turn done.  The 
submarine outside (xxx) will be attacked, leaving the attacking 
submarine visible when it should not be (in 2.0 or 2.0.99).  Move the 
submarine that can "see" the enemy submarine northeast, and you'll get a 
client assertion (2.0.99 only - 2.0 has this assert removed).

Under the patch I believe this to be fixed.

-jason

Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.157
diff -u -r1.157 maphand.c
--- server/maphand.c    14 Feb 2005 22:52:41 -0000      1.157
+++ server/maphand.c    15 Feb 2005 02:42:00 -0000
@@ -605,6 +605,31 @@
   } adjc_iterate_end;
 }
 
+/*************************************************************************
+  Checks for hidden units around (x,y).  Such units can be invisible even
+  on a KNOWN_AND_SEEN tile, so fogging might not hide them.
+
+  Note, this must be called after the unit/vision source at ptile has
+  been removed, unlike remove_unit_sight_points.
+************************************************************************/
+void conceal_hidden_units(struct player *pplayer, struct tile *ptile)
+{
+  /* Remove vision of submarines.  This is extremely ugly and inefficient. */
+  adjc_iterate(ptile, tile1) {
+    unit_list_iterate(tile1->units, phidden_unit) {
+      if (phidden_unit->transported_by == -1
+         && is_hiding_unit(phidden_unit)) {
+       players_iterate(pplayer2) {
+         if ((pplayer2 == pplayer || really_gives_vision(pplayer, pplayer2))
+             && !can_player_see_unit(pplayer2, phidden_unit)) {
+           unit_goes_out_of_sight(pplayer2, phidden_unit);
+         }
+       } players_iterate_end;
+      }
+    } unit_list_iterate_end;
+  } adjc_iterate_end;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
Index: server/maphand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v
retrieving revision 1.52
diff -u -r1.52 maphand.h
--- server/maphand.h    29 Jan 2005 19:01:32 -0000      1.52
+++ server/maphand.h    15 Feb 2005 02:42:00 -0000
@@ -65,6 +65,7 @@
 void send_all_known_tiles(struct conn_list *dest);
 void send_tile_info(struct conn_list *dest, struct tile *ptile);
 void reveal_hidden_units(struct player *pplayer, struct tile *ptile);
+void conceal_hidden_units(struct player *pplayer, struct tile *ptile);
 void unfog_area(struct player *pplayer, struct tile *ptile, int len);
 void fog_area(struct player *pplayer, struct tile *ptile, int len);
 void upgrade_city_rails(struct player *pplayer, bool discovery);
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.320
diff -u -r1.320 unittools.c
--- server/unittools.c  14 Feb 2005 22:52:42 -0000      1.320
+++ server/unittools.c  15 Feb 2005 02:42:01 -0000
@@ -1524,6 +1524,7 @@
   struct city *pcity = map_get_city(punit->tile);
   struct city *phomecity = find_city_by_id(punit->homecity);
   struct tile *unit_tile = punit->tile;
+  struct player *unitowner = unit_owner(punit);
 
 #ifndef NDEBUG
   unit_list_iterate(punit->tile->units, pcargo) {
@@ -1562,6 +1563,9 @@
   game_remove_unit(punit);
   punit = NULL;
 
+  /* Hide any submarines that are no longer visible. */
+  conceal_hidden_units(unitowner, unit_tile);
+
   /* This unit may have blocked tiles of adjacent cities. Update them. */
   map_city_radius_iterate(unit_tile, ptile1) {
     struct city *pcity = map_get_city(ptile1);

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