# HG changeset patch # User rubidium # Date 1186335784 0 # Node ID 51db351a3313b68142094678eaa57bad030904d5 # Parent 6aa1fd67a91466e766bb316af9f93a53e47e2fd4 (svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(. diff -r 6aa1fd67a914 -r 51db351a3313 src/aircraft.h --- a/src/aircraft.h Sun Aug 05 14:08:38 2007 +0000 +++ b/src/aircraft.h Sun Aug 05 17:43:04 2007 +0000 @@ -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(); diff -r 6aa1fd67a914 -r 51db351a3313 src/roadveh.h --- a/src/roadveh.h Sun Aug 05 14:08:38 2007 +0000 +++ b/src/roadveh.h Sun Aug 05 17:43:04 2007 +0000 @@ -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(); diff -r 6aa1fd67a914 -r 51db351a3313 src/ship.h --- a/src/ship.h Sun Aug 05 14:08:38 2007 +0000 +++ b/src/ship.h Sun Aug 05 17:43:04 2007 +0000 @@ -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(); diff -r 6aa1fd67a914 -r 51db351a3313 src/train.h --- a/src/train.h Sun Aug 05 14:08:38 2007 +0000 +++ b/src/train.h Sun Aug 05 17:43:04 2007 +0000 @@ -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(); diff -r 6aa1fd67a914 -r 51db351a3313 src/vehicle.cpp --- a/src/vehicle.cpp Sun Aug 05 14:08:38 2007 +0000 +++ b/src/vehicle.cpp Sun Aug 05 17:43:04 2007 +0000 @@ -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(); } diff -r 6aa1fd67a914 -r 51db351a3313 src/vehicle.h --- a/src/vehicle.h Sun Aug 05 14:08:38 2007 +0000 +++ b/src/vehicle.h Sun Aug 05 17:43:04 2007 +0000 @@ -347,6 +347,8 @@ /** 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();