Mercurial > hg > openttd
changeset 7412:6682e85ffa07 draft
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 05 Aug 2007 17:43:04 +0000 |
parents | 63e7d21724ec |
children | 571c87eed06c |
files | src/aircraft.h src/roadveh.h src/ship.h src/train.h src/vehicle.cpp src/vehicle.h |
diffstat | 6 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft.h +++ b/src/aircraft.h @@ -128,7 +128,7 @@ Aircraft() { this->type = VEH_AIRCRAFT; } /** We want to 'destruct' the right class. */ - virtual ~Aircraft() {} + virtual ~Aircraft() { this->PreDestructor(); } const char *GetTypeString() const { return "aircraft"; } void MarkDirty();
--- a/src/roadveh.h +++ b/src/roadveh.h @@ -72,7 +72,7 @@ RoadVehicle() { this->type = VEH_ROAD; } /** We want to 'destruct' the right class. */ - virtual ~RoadVehicle() {} + virtual ~RoadVehicle() { this->PreDestructor(); } const char *GetTypeString() const { return "road vehicle"; } void MarkDirty();
--- a/src/ship.h +++ b/src/ship.h @@ -37,7 +37,7 @@ Ship() { this->type = VEH_SHIP; } /** We want to 'destruct' the right class. */ - virtual ~Ship() {} + virtual ~Ship() { this->PreDestructor(); } const char *GetTypeString() const { return "ship"; } void MarkDirty();
--- a/src/train.h +++ b/src/train.h @@ -262,7 +262,7 @@ Train() { this->type = VEH_TRAIN; } /** We want to 'destruct' the right class. */ - virtual ~Train() {} + virtual ~Train() { this->PreDestructor(); } const char *GetTypeString() const { return "train"; } void MarkDirty();
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -562,7 +562,7 @@ } } -Vehicle::~Vehicle() +void Vehicle::PreDestructor() { if (IsValidStationID(this->last_station_visited)) { GetStation(this->last_station_visited)->loading_vehicles.remove(this); @@ -579,8 +579,6 @@ if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id); } - DeleteVehicleNews(this->index, INVALID_STRING_ID); - this->QuickFree(); if (this->type == VEH_ROAD) ClearSlot(this); @@ -589,10 +587,7 @@ } this->cargo.Truncate(0); - UpdateVehiclePosHash(this, INVALID_COORD, 0); - this->next_hash = NULL; - this->next_new_hash = NULL; - if (IsPlayerBuildableVehicleType(this)) DeleteVehicleOrders(this); + DeleteVehicleOrders(this); /* Now remove any artic part. This will trigger an other * destroy vehicle, which on his turn can remove any @@ -600,6 +595,15 @@ if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) { 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(); }