diff options
author | bjarni <bjarni@openttd.org> | 2008-05-07 13:11:33 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2008-05-07 13:11:33 +0000 |
commit | 0cfd2baa3c5d5f5e283bfde3e7b7dd8ec3f0d2f8 (patch) | |
tree | f4a1b28a05b28cb49bc41e6303732558b9682ef9 | |
parent | 3d5567ccf767160de35b67bd165abe3badf487fe (diff) | |
download | openttd-0cfd2baa3c5d5f5e283bfde3e7b7dd8ec3f0d2f8.tar.xz |
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
-rw-r--r-- | src/vehicle.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c624f97b6..73f2bb0d6 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2746,6 +2746,10 @@ Vehicle* BackuppedVehicle::RestoreBackupVehicle(Vehicle *v, Player *p) assert(v->owner == p->index); + /* Cache the result of the vehicle type check since it will not change + * and we need this check once for every run though the loop. */ + bool is_road_veh = v->type == VEH_ROAD; + while (true) { Vehicle *dest = GetVehicle(backup->index); /* The vehicle should be free since we are restoring something we just sold. */ @@ -2761,6 +2765,12 @@ Vehicle* BackuppedVehicle::RestoreBackupVehicle(Vehicle *v, Player *p) dest->left_coord = INVALID_COORD; UpdateVehiclePosHash(dest, INVALID_COORD, 0); + if (is_road_veh) { + /* Removed the slot in the road vehicles as the slot is gone. + * We don't want a pointer to a slot that's gone. */ + dest->u.road.slot = NULL; + } + if (!dest->cargo.Empty()) { /* The vehicle in question contains some cargo. * However we lost the list so we will have to recreate it. |