summaryrefslogtreecommitdiff
path: root/src/saveload/afterload.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-02-08 18:34:13 +0000
committersmatz <smatz@openttd.org>2011-02-08 18:34:13 +0000
commit887a7724dc3f68cdd3d0c566c66adf00696e4bc0 (patch)
tree00a9055a6bc84b0f9d278e3a8faac022dd0a3778 /src/saveload/afterload.cpp
parent364ef8e6e6342f8f777da561571422c8c57c402b (diff)
downloadopenttd-887a7724dc3f68cdd3d0c566c66adf00696e4bc0.tar.xz
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
Diffstat (limited to 'src/saveload/afterload.cpp')
-rw-r--r--src/saveload/afterload.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index f73ef2189..17ac9bc81 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -782,11 +782,18 @@ bool AfterLoadGame()
case STATION_TRUCK:
case STATION_BUS:
if (IsSavegameVersionBefore(6)) {
+ /* Before version 5 you could not have more than 250 stations.
+ * Version 6 adds large maps, so you could only place 253*253
+ * road stops on a map (no freeform edges) = 64009. So, yes
+ * someone could in theory create such a full map to trigger
+ * this assertion, it's safe to assume that's only something
+ * theoretical and does not happen in normal games. */
+ assert(RoadStop::CanAllocateItem());
+
/* From this version on there can be multiple road stops of the
* same type per station. Convert the existing stops to the new
* internal data structure. */
RoadStop *rs = new RoadStop(t);
- if (rs == NULL) error("Too many road stops in savegame");
RoadStop **head =
IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
@@ -1928,6 +1935,12 @@ bool AfterLoadGame()
ObjectType type = GetObjectType(t);
int size = type == OBJECT_HQ ? 2 : 1;
+ if (!Object::CanAllocateItem()) {
+ /* Nice... you managed to place 64k lighthouses and
+ * antennae on the map... boohoo. */
+ SlError(STR_ERROR_TOO_MANY_OBJECTS);
+ }
+
Object *o = new Object();
o->location.tile = t;
o->location.w = size;
@@ -2024,6 +2037,10 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) {
std::list<Vehicle *>::iterator iter;
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
+ /* There are always as many CargoPayments as Vehicles. We need to make the
+ * assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
+ assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
+ assert(CargoPayment::CanAllocateItem());
Vehicle *v = *iter;
if (v->cargo_payment == NULL) v->cargo_payment = new CargoPayment(v);
}