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

2008/5/2 Marko Lindqvist:
>
>   I set up game and saved in - still in pregame. Loading this savegame
>  leads to failing sanity checks and crashes.

 This turned out to be problem with teams when ever number of players
is lower after the save than before it. Players in high indices didn't
release their team.

 Fix attached.

 There also was now block with comment like this:
/* Assign players with no team listed onto an empty team. */
 This is never needed, as player_load_main() already has stricter
handling; if there is no empty teams available, player is assigned to
smallest team.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/sanitycheck.c 
freeciv/server/sanitycheck.c
--- freeciv/server/sanitycheck.c        2008-05-02 20:21:04.000000000 +0300
+++ freeciv/server/sanitycheck.c        2008-05-08 13:04:01.000000000 +0300
@@ -663,7 +663,7 @@
 
   memset(count, 0, sizeof(count));
   players_iterate(pplayer) {
-    /* For the moment, all players (including observers) have teams. */
+    /* For the moment, all players have teams. */
     SANITY_CHECK(pplayer->team != NULL);
     if (pplayer->team) {
       count[team_index(pplayer->team)]++;
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c   2008-04-05 13:11:54.000000000 +0300
+++ freeciv/server/savegame.c   2008-05-08 13:36:27.000000000 +0300
@@ -1743,15 +1743,16 @@
   struct player_research *research;
   struct nation_type *pnation;
 
-  /* not all players have teams */
+  /* All players should now have teams. This is not the case with
+   * old savegames. */
   id = secfile_lookup_int_default(file, -1, "player%d.team_no", plrno);
   pteam = team_by_number(id);
   if (pteam == NULL) {
     pteam = find_empty_team();
   }
-  
+
   team_add_player(plr, pteam);
-  
+
   research = get_player_research(plr);
 
   server_player_init(plr, TRUE, FALSE);
@@ -4107,6 +4108,13 @@
     load_rulesets();
   }
 
+  /* Free all players from teams, and teams from players
+   * This must be done while players_iterate() still iterates
+   * to the previous number of players. */
+  players_iterate(pplayer) {
+    team_remove_player(pplayer);
+  } players_iterate_end;
+
   game.info.nplayers      = secfile_lookup_int(file, "game.nplayers");
 
 
@@ -4311,13 +4319,6 @@
                nation_plural_for_player(pplayer));
       }
     } players_iterate_end;
-
-    /* Assign players with no team listed onto an empty team. */
-    players_iterate(pplayer) {
-      if (!pplayer->team) {
-       team_add_player(pplayer, find_empty_team());
-      }
-    } players_iterate_end;
     
     /* Sanity check alliances, prevent allied-with-ally-of-enemy */
     players_iterate(plr) {
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to