Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13465) Choosing nation after game has started in prega
Home

[Freeciv-Dev] (PR#13465) Choosing nation after game has started in prega

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mstefek@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#13465) Choosing nation after game has started in pregame screen
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Jul 2005 10:08:28 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [mstefek - Wed Jul 13 10:19:38 2005]:
> 
> CVS, gtk client
> When you connect to already started game with user which doesn't have
> player assigned and you press on the nation column in the pregame player
> list you get this crash:
> #2  0xb78ce2df in __assert_fail () from /lib/tls/libc.so.6
> No symbol table info available.
> #3  0x080a9e06 in get_player (player_id=-1) at game.c:514
> No locals.
> #4  0x08136ada in playerlist_event (widget=0x83a2c18, event=0x8a81478,
>     data=0x0) at pages.c:1034
>         tree = (GtkTreeView *) 0x83a2c18
>         model = (GtkTreeModel *) 0x839ba98
>         iter = {stamp = 1139409867, user_data = 0x8b3c240, user_data2
= 0x0,
>   user_data3 = 0x0}
>         path = (GtkTreePath *) 0x8d53f80
>         column = (GtkTreeViewColumn *) 0x8a5f260
>         player_no = -1
>         pplayer = (struct player *) 0xbffff300

It seems this assertion is spurious.  This patch fixes it.

-jason

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.228
diff -p -u -r1.228 game.c
--- common/game.c       14 Jul 2005 19:25:45 -0000      1.228
+++ common/game.c       15 Jul 2005 17:07:45 -0000
@@ -511,16 +511,24 @@ void game_renumber_players(int plrno)
 /**************************************************************************
 get_player() - Return player struct pointer corresponding to player_id.
                Eg: player_id = punit->owner, or pcity->owner
+
+  You can retrieve players that are no in the game (with IDs larger than
+  game.info.nplayers).  An out-of-range player request will return NULL.
 **************************************************************************/
 struct player *get_player(int player_id)
 {
   if (player_id < 0 || player_id >= ARRAY_SIZE(game.players)) {
-    assert(player_id >= 0 && player_id < ARRAY_SIZE(game.players));
+    /* This isn't an error; some callers rely on this behavior. */
     return NULL;
   }
+  assert(game.players[player_id].player_no == player_id);
   return &game.players[player_id];
 }
 
+/**************************************************************************
+  Return TRUE iff the player ID refers to an in-game player.  Unlike
+  get_player any index larger than nplayers is not considered "valid".
+**************************************************************************/
 bool is_valid_player_id(int player_id)
 {
   return player_id >= 0 && player_id < game.info.nplayers;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13465) Choosing nation after game has started in pregame screen, Jason Short <=