mirror of https://github.com/OpenTTD/OpenTTD
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
parent
f6933e1870
commit
ab5fa3add2
|
@ -128,7 +128,7 @@ struct Aircraft : public Vehicle {
|
||||||
Aircraft() { this->type = VEH_AIRCRAFT; }
|
Aircraft() { this->type = VEH_AIRCRAFT; }
|
||||||
|
|
||||||
/** We want to 'destruct' the right class. */
|
/** We want to 'destruct' the right class. */
|
||||||
virtual ~Aircraft() {}
|
virtual ~Aircraft() { this->PreDestructor(); }
|
||||||
|
|
||||||
const char *GetTypeString() const { return "aircraft"; }
|
const char *GetTypeString() const { return "aircraft"; }
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct RoadVehicle : public Vehicle {
|
||||||
RoadVehicle() { this->type = VEH_ROAD; }
|
RoadVehicle() { this->type = VEH_ROAD; }
|
||||||
|
|
||||||
/** We want to 'destruct' the right class. */
|
/** We want to 'destruct' the right class. */
|
||||||
virtual ~RoadVehicle() {}
|
virtual ~RoadVehicle() { this->PreDestructor(); }
|
||||||
|
|
||||||
const char *GetTypeString() const { return "road vehicle"; }
|
const char *GetTypeString() const { return "road vehicle"; }
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct Ship: public Vehicle {
|
||||||
Ship() { this->type = VEH_SHIP; }
|
Ship() { this->type = VEH_SHIP; }
|
||||||
|
|
||||||
/** We want to 'destruct' the right class. */
|
/** We want to 'destruct' the right class. */
|
||||||
virtual ~Ship() {}
|
virtual ~Ship() { this->PreDestructor(); }
|
||||||
|
|
||||||
const char *GetTypeString() const { return "ship"; }
|
const char *GetTypeString() const { return "ship"; }
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
|
|
|
@ -262,7 +262,7 @@ struct Train : public Vehicle {
|
||||||
Train() { this->type = VEH_TRAIN; }
|
Train() { this->type = VEH_TRAIN; }
|
||||||
|
|
||||||
/** We want to 'destruct' the right class. */
|
/** We want to 'destruct' the right class. */
|
||||||
virtual ~Train() {}
|
virtual ~Train() { this->PreDestructor(); }
|
||||||
|
|
||||||
const char *GetTypeString() const { return "train"; }
|
const char *GetTypeString() const { return "train"; }
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
|
|
|
@ -562,7 +562,7 @@ bool IsEngineCountable(const Vehicle *v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vehicle::~Vehicle()
|
void Vehicle::PreDestructor()
|
||||||
{
|
{
|
||||||
if (IsValidStationID(this->last_station_visited)) {
|
if (IsValidStationID(this->last_station_visited)) {
|
||||||
GetStation(this->last_station_visited)->loading_vehicles.remove(this);
|
GetStation(this->last_station_visited)->loading_vehicles.remove(this);
|
||||||
|
@ -579,8 +579,6 @@ Vehicle::~Vehicle()
|
||||||
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
|
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteVehicleNews(this->index, INVALID_STRING_ID);
|
|
||||||
|
|
||||||
this->QuickFree();
|
this->QuickFree();
|
||||||
if (this->type == VEH_ROAD) ClearSlot(this);
|
if (this->type == VEH_ROAD) ClearSlot(this);
|
||||||
|
|
||||||
|
@ -589,10 +587,7 @@ Vehicle::~Vehicle()
|
||||||
}
|
}
|
||||||
|
|
||||||
this->cargo.Truncate(0);
|
this->cargo.Truncate(0);
|
||||||
UpdateVehiclePosHash(this, INVALID_COORD, 0);
|
DeleteVehicleOrders(this);
|
||||||
this->next_hash = NULL;
|
|
||||||
this->next_new_hash = NULL;
|
|
||||||
if (IsPlayerBuildableVehicleType(this)) DeleteVehicleOrders(this);
|
|
||||||
|
|
||||||
/* Now remove any artic part. This will trigger an other
|
/* Now remove any artic part. This will trigger an other
|
||||||
* destroy vehicle, which on his turn can remove any
|
* destroy vehicle, which on his turn can remove any
|
||||||
|
@ -600,6 +595,15 @@ Vehicle::~Vehicle()
|
||||||
if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) {
|
if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) {
|
||||||
delete this->next;
|
delete this->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vehicle::~Vehicle()
|
||||||
|
{
|
||||||
|
UpdateVehiclePosHash(this, INVALID_COORD, 0);
|
||||||
|
this->next_hash = NULL;
|
||||||
|
this->next_new_hash = NULL;
|
||||||
|
|
||||||
|
DeleteVehicleNews(this->index, INVALID_STRING_ID);
|
||||||
|
|
||||||
new (this) InvalidVehicle();
|
new (this) InvalidVehicle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,6 +347,8 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
|
||||||
/** Create a new vehicle */
|
/** Create a new vehicle */
|
||||||
Vehicle();
|
Vehicle();
|
||||||
|
|
||||||
|
/** Destroy all stuff that (still) needs the virtual functions to work properly */
|
||||||
|
void PreDestructor();
|
||||||
/** We want to 'destruct' the right class. */
|
/** We want to 'destruct' the right class. */
|
||||||
virtual ~Vehicle();
|
virtual ~Vehicle();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue