Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12388: Vehicle::CopyVehicleConfigAndStatistics not releasing unit number #12389

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/train_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,7 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID
}
/* Remove stuff not valid anymore for non-front engines. */
DeleteVehicleOrders(src);
Company::Get(src->owner)->freeunits[src->type].ReleaseID(src->unitnumber);
src->unitnumber = 0;
src->ReleaseUnitNumber();
src->name.clear();
}

Expand Down
9 changes: 9 additions & 0 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,15 @@ void Vehicle::ResetRefitCaps()
for (Vehicle *v = this; v != nullptr; v = v->Next()) v->refit_cap = v->cargo_cap;
}

/**
* Release the vehicle's unit number.
*/
void Vehicle::ReleaseUnitNumber()
{
Company::Get(this->owner)->freeunits[this->type].ReleaseID(this->unitnumber);
this->unitnumber = 0;
}

/**
* Handle the loading of the vehicle; when not it skips through dummy
* orders and does nothing in all other cases.
Expand Down
3 changes: 3 additions & 0 deletions src/vehicle_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist

void ResetRefitCaps();

void ReleaseUnitNumber();

/**
* Copy certain configurations and statistics of a vehicle after successful autoreplace/renew
* The function shall copy everything that cannot be copied by a command (like orders / group etc),
Expand All @@ -760,6 +762,7 @@ struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist
{
this->CopyConsistPropertiesFrom(src);

this->ReleaseUnitNumber();
this->unitnumber = src->unitnumber;

this->current_order = src->current_order;
Expand Down