Author: jtn
Date: Thu Aug 20 01:30:42 2015
New Revision: 29600

URL: http://svn.gna.org/viewcvs/freeciv?rev=29600&view=rev
Log:
When loading savegame, recalculate city illness only after loading all
trade partners.
This was causing a crash on loading savegames.

Crash reported by SÅ‚awomir Lach (lachu@gna) and others.

See gna bug #23786.

Modified:
    trunk/server/savegame.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c

Modified: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=29600&r1=29599&r2=29600&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Thu Aug 20 01:30:42 2015
@@ -2349,12 +2349,6 @@
     pcity->turn_plague =
       secfile_lookup_int_default(file, 0, "player%d.c%d.turn_plague",
                                  plrno,i);
-    if (game.info.illness_on) {
-      /* recalculate city illness */
-      pcity->server.illness
-        = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), NULL);
-    }
-
     fc_assert_exit_msg(secfile_lookup_int(file, &pcity->anarchy,
                                           "player%d.c%d.anarchy", plrno, i),
                        "%s", secfile_error());
@@ -3988,6 +3982,16 @@
       } unit_list_iterate_end;
       /* Load transporter status. */
       player_load_units_transporter(pplayer, file);
+      /* Update cached city illness. This can depend on trade routes,
+       * so can't be calculated until all players have been loaded. */
+      if (game.info.illness_on) {
+        city_list_iterate(pplayer->cities, pcity) {
+          pcity->server.illness
+            = city_illness_calc(pcity, NULL, NULL,
+                                &(pcity->illness_trade), NULL);
+        } city_list_iterate_end;
+      }
+
     } players_iterate_end;
 
     /* Free worked tiles map */

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=29600&r1=29599&r2=29600&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Thu Aug 20 01:30:42 2015
@@ -2474,6 +2474,16 @@
     } players_iterate_alive_end;
   } players_iterate_alive_end;
 
+  /* Update cached city illness. This can depend on trade routes,
+   * so can't be calculated until all players have been loaded. */
+  if (game.info.illness_on) {
+    cities_iterate(pcity) {
+      pcity->server.illness
+        = city_illness_calc(pcity, NULL, NULL,
+                            &(pcity->illness_trade), NULL);
+    } cities_iterate_end;
+  }
+
   /* Update all city information.  This must come after all cities are
    * loaded (in player_load) but before player (dumb) cities are loaded
    * in player_load_vision(). */
@@ -3122,11 +3132,6 @@
 
   pcity->turn_plague =
     secfile_lookup_int_default(loading->file, 0, "%s.turn_plague", citystr);
-  if (game.info.illness_on) {
-    /* recalculate city illness */
-    pcity->server.illness = city_illness_calc(pcity, NULL, NULL,
-                                              &(pcity->illness_trade), NULL);
-  }
 
   sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->anarchy,
                                     "%s.anarchy", citystr),

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=29600&r1=29599&r2=29600&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Thu Aug 20 01:30:42 2015
@@ -3365,6 +3365,16 @@
     } players_iterate_alive_end;
   } players_iterate_alive_end;
 
+  /* Update cached city illness. This can depend on trade routes,
+   * so can't be calculated until all players have been loaded. */
+  if (game.info.illness_on) {
+    cities_iterate(pcity) {
+      pcity->server.illness
+        = city_illness_calc(pcity, NULL, NULL,
+                            &(pcity->illness_trade), NULL);
+    } cities_iterate_end;
+  }
+
   /* Update all city information.  This must come after all cities are
    * loaded (in player_load) but before player (dumb) cities are loaded
    * in player_load_vision(). */
@@ -4312,11 +4322,6 @@
 
   pcity->turn_plague =
     secfile_lookup_int_default(loading->file, 0, "%s.turn_plague", citystr);
-  if (game.info.illness_on) {
-    /* recalculate city illness */
-    pcity->server.illness = city_illness_calc(pcity, NULL, NULL,
-                                              &(pcity->illness_trade), NULL);
-  }
 
   sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->anarchy,
                                     "%s.anarchy", citystr),


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to