src/vehicle.cpp
changeset 9128 f4b41e7c282e
parent 9111 48ce04029fe4
child 9146 dbe2317185eb
--- a/src/vehicle.cpp	Wed May 07 13:10:15 2008 +0000
+++ b/src/vehicle.cpp	Wed May 07 13:11:33 2008 +0000
@@ -2746,6 +2746,10 @@
 
 	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 @@
 		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.