Index: src/vehicle.cpp =================================================================== --- src/vehicle.cpp (Revision 13681) +++ src/vehicle.cpp (Arbeitskopie) @@ -2489,19 +2489,16 @@ for (; 0 < length; original = original->Next(), copy++, length--) { /* First we need to copy the vehicle itself. - * However there is an issue as the cargo list isn't copied. - * To avoid restoring invalid pointers we start by swapping the cargo list with an empty one. */ - CargoList::List empty_packets; - original->cargo.packets.swap(empty_packets); + * After the copy, the cargo list of the new copy will still point + * to the same memory of the original list. As the original list will + * likely be destroyed, this leads to an invalid cargo list in our + * backup. The cargo packets itself are saved separately later on. */ memcpy(copy, original, sizeof(Vehicle)); /* No need to do anything else if the cargo list is empty. * It really doesn't matter if we swap an empty list with an empty list. */ if (original->cargo.Empty()) continue; - /* And now we swap the cargo lists back. The vehicle now has it's cargo again. */ - original->cargo.packets.swap(empty_packets); - /* The vehicle contains some cargo so we will back up the cargo as well. * We only need to store the packets and not which vehicle they came from. * We will still be able to put them together with the right vehicle when restoring. */ @@ -2535,6 +2532,8 @@ /* The vehicle should be free since we are restoring something we just sold. */ assert(!dest->IsValid()); memcpy(dest, backup, sizeof(Vehicle)); + /* Our backup vehicle has an invalid cargo list, so construct a new one in-place. */ + new(&dest->cargo.packets) CargoList::List(); /* We decreased the engine count when we sold the engines so we will increase it again. */ if (IsEngineCountable(backup)) {