summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-05 17:43:04 +0000
committerrubidium <rubidium@openttd.org>2007-08-05 17:43:04 +0000
commitab5fa3add2f5f2feeb8f48127f6ee5ab69d42f65 (patch)
tree0eafac3ddee78188054a0844f0525a87e5435999
parentf6933e18701de289a439b658282549079d511b19 (diff)
downloadopenttd-ab5fa3add2f5f2feeb8f48127f6ee5ab69d42f65.tar.xz
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
-rw-r--r--src/aircraft.h2
-rw-r--r--src/roadveh.h2
-rw-r--r--src/ship.h2
-rw-r--r--src/train.h2
-rw-r--r--src/vehicle.cpp18
-rw-r--r--src/vehicle.h2
6 files changed, 17 insertions, 11 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index 2f5f14b90..ccf9a242b 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -128,7 +128,7 @@ struct Aircraft : public Vehicle {
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();
diff --git a/src/roadveh.h b/src/roadveh.h
index a66c01263..95a4f2470 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -72,7 +72,7 @@ struct RoadVehicle : public Vehicle {
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();
diff --git a/src/ship.h b/src/ship.h
index 0ca73ee95..304872758 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -37,7 +37,7 @@ struct Ship: public Vehicle {
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();
diff --git a/src/train.h b/src/train.h
index 54eb23442..8d16a988e 100644
--- a/src/train.h
+++ b/src/train.h
@@ -262,7 +262,7 @@ struct Train : public Vehicle {
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();
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index c2fbe0548..c845a00b0 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -562,7 +562,7 @@ bool IsEngineCountable(const Vehicle *v)
}
}
-Vehicle::~Vehicle()
+void Vehicle::PreDestructor()
{
if (IsValidStationID(this->last_station_visited)) {
GetStation(this->last_station_visited)->loading_vehicles.remove(this);
@@ -579,8 +579,6 @@ Vehicle::~Vehicle()
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 @@ Vehicle::~Vehicle()
}
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 @@ Vehicle::~Vehicle()
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();
}
diff --git a/src/vehicle.h b/src/vehicle.h
index bdd646987..743987763 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -347,6 +347,8 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
/** Create a new vehicle */
Vehicle();
+ /** Destroy all stuff that (still) needs the virtual functions to work properly */
+ void PreDestructor();
/** We want to 'destruct' the right class. */
virtual ~Vehicle();