mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22111) -Codechange/fix-ish: upon cleaning a pool a destructor should not delete items from other pools
This commit is contained in:
parent
f575b45bae
commit
68bc93f950
|
@ -154,6 +154,16 @@ CargoList<Tinst>::~CargoList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty the cargo list, but don't free the cargo packets;
|
||||||
|
* the cargo packets are cleaned by CargoPacket's CleanPool.
|
||||||
|
*/
|
||||||
|
template <class Tinst>
|
||||||
|
void CargoList<Tinst>::OnCleanPool()
|
||||||
|
{
|
||||||
|
this->packets.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the cached values to reflect the removal of this packet.
|
* Update the cached values to reflect the removal of this packet.
|
||||||
* Decreases count and days_in_transit.
|
* Decreases count and days_in_transit.
|
||||||
|
|
|
@ -197,6 +197,8 @@ public:
|
||||||
|
|
||||||
~CargoList();
|
~CargoList();
|
||||||
|
|
||||||
|
void OnCleanPool();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the cargo packet list (so you can iterate over it etc).
|
* Returns a pointer to the cargo packet list (so you can iterate over it etc).
|
||||||
* @return Pointer to the packet list.
|
* @return Pointer to the packet list.
|
||||||
|
|
|
@ -70,7 +70,12 @@ Station::Station(TileIndex tile) :
|
||||||
*/
|
*/
|
||||||
Station::~Station()
|
Station::~Station()
|
||||||
{
|
{
|
||||||
if (CleaningPool()) return;
|
if (CleaningPool()) {
|
||||||
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
||||||
|
this->goods[c].cargo.OnCleanPool();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!this->loading_vehicles.empty()) {
|
while (!this->loading_vehicles.empty()) {
|
||||||
this->loading_vehicles.front()->LeaveStation();
|
this->loading_vehicles.front()->LeaveStation();
|
||||||
|
|
|
@ -736,7 +736,10 @@ Vehicle::~Vehicle()
|
||||||
{
|
{
|
||||||
free(this->name);
|
free(this->name);
|
||||||
|
|
||||||
if (CleaningPool()) return;
|
if (CleaningPool()) {
|
||||||
|
this->cargo.OnCleanPool();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
|
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
|
||||||
* it may happen that vehicle chain is deleted when visible */
|
* it may happen that vehicle chain is deleted when visible */
|
||||||
|
|
Loading…
Reference in New Issue