From c5ae45c764b374d91ad7f05dbe65f8167ec81804 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 29 May 2016 12:21:40 +0000 Subject: [PATCH 1/6] (svn r27583) -Fix [FS#6415]: Do not decrease the column width of depot windows when vehicles with high unitnumbers leave. (Airbus) --- src/depot_gui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 4aff4700b3..24a14b8334 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -663,7 +663,8 @@ struct DepotWindow : Window { DepotSortList(&this->vehicle_list); uint new_unitnumber_digits = GetUnitNumberDigits(this->vehicle_list); - if (this->unitnumber_digits != new_unitnumber_digits) { + /* Only increase the size; do not decrease to prevent constant changes */ + if (this->unitnumber_digits < new_unitnumber_digits) { this->unitnumber_digits = new_unitnumber_digits; this->ReInit(); } From a66e0ff1f45c1371c881205f0878e9e3110b3518 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 29 May 2016 13:33:20 +0000 Subject: [PATCH 2/6] (svn r27584) -Codechange: Add some assertions about Vehicle::cargo_payment. --- src/economy.cpp | 1 + src/vehicle.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/economy.cpp b/src/economy.cpp index d78d2cccec..121fc67332 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1651,6 +1651,7 @@ static void LoadUnloadVehicle(Vehicle *front) uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, load_amount) : cargo_count; bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here? + assert(payment != NULL); payment->SetCargo(v->cargo_type); if (!HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE) && v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER) > 0) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index a482520f25..da2cfeb807 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -216,7 +216,7 @@ uint Vehicle::Crash(bool flooded) SetWindowDirty(WC_VEHICLE_DEPOT, this->tile); delete this->cargo_payment; - this->cargo_payment = NULL; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment return RandomRange(pass + 1); // Randomise deceased passengers. } @@ -746,6 +746,7 @@ void Vehicle::PreDestructor() HideFillingPercent(&this->fill_percent_te_id); this->CancelReservation(INVALID_STATION, st); delete this->cargo_payment; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment } if (this->IsEngineCountable()) { @@ -2085,6 +2086,7 @@ void Vehicle::LeaveStation() assert(this->current_order.IsType(OT_LOADING)); delete this->cargo_payment; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment /* Only update the timetable if the vehicle was supposed to stop here. */ if (this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); From 0b2f8c13a26c9772fcd215b8e22132eb1c0d9e82 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 29 May 2016 13:35:17 +0000 Subject: [PATCH 3/6] (svn r27585) -Fix [FS#6437]: Enforce a non-zero load amount for all vehicles, so that vehicles can process their cargo reservations. --- src/economy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/economy.cpp b/src/economy.cpp index 121fc67332..cdfa059e86 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1317,7 +1317,8 @@ static uint GetLoadAmount(Vehicle *v) /* Scale load amount the same as capacity */ if (HasBit(e->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER) && !air_mail) load_amount = CeilDiv(load_amount * CargoSpec::Get(v->cargo_type)->multiplier, 0x100); - return load_amount; + /* Zero load amount breaks a lot of things. */ + return max(1u, load_amount); } /** From 05a91106b864cdcbbdcd7387c7a39058041572a6 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 29 May 2016 14:14:52 +0000 Subject: [PATCH 4/6] (svn r27586) -Fix [FS#6410]: Automatic servicing of road vehicles compared path finder costs with tile distances, thus vehicles went to depots which were factor 100 too far away. (juanjo) --- src/pathfinder/yapf/yapf_road.cpp | 40 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 4c26d7b095..380b641da7 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -430,29 +430,34 @@ public: return true; } - static bool stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) + static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { Tpf pf; - return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile); + return pf.FindNearestDepot(v, tile, td, max_distance); } - inline bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) + /** + * Find the best depot for a road vehicle. + * @param v Vehicle + * @param tile Tile of the vehicle. + * @param td Trackdir of the vehicle. + * @param max_distance max length (penalty) for paths. + * @todo max_distance not used by YAPF for road vehicles. + * It can be removed or copy the SetMaxCost() strategy + * applied in YAPF for rail. The best depot can be at + * a distance greater than max_distance. + */ + inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { - /* set origin and destination nodes */ + /* Set origin. */ Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); - /* find the best path */ - bool bFound = Yapf().FindPath(v); - if (!bFound) return false; + /* Find the best path and return if no depot is found. */ + if (!Yapf().FindPath(v)) return FindDepotData(); - /* some path found - * get found depot tile */ + /* Return the cost of the best path and its depot. */ Node *n = Yapf().GetBestNode(); - - if (max_distance > 0 && n->m_cost > max_distance * YAPF_TILE_LENGTH) return false; - - *depot_tile = n->m_segment_last_tile; - return true; + return FindDepotData(n->m_segment_last_tile, n->m_cost); } }; @@ -504,7 +509,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist } /* default is YAPF type 2 */ - typedef bool (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int, TileIndex*); + typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int); PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; /* check if non-default YAPF type should be used */ @@ -512,8 +517,5 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg } - FindDepotData fdd; - bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, &fdd.tile); - fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND - return fdd; + return pfnFindNearestDepot(v, tile, trackdir, max_distance); } From 842aaf7cdd9cba079ccff28aa1cf70da28c0042e Mon Sep 17 00:00:00 2001 From: frosch Date: Mon, 30 May 2016 21:03:11 +0000 Subject: [PATCH 5/6] (svn r27594) -Fix [FS#6473]: [Script] Kill scripts, when a non-suspendable valuator call takes way too long. --- src/script/api/script_list.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index bdbc1209bd..d0c72b5bb1 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -11,6 +11,7 @@ #include "../../stdafx.h" #include "script_list.hpp" +#include "script_controller.hpp" #include "../../debug.h" #include "../../script/squirrel.hpp" @@ -905,6 +906,16 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm) } } + /* Kill the script when the valuator call takes way too long. + * Triggered by nesting valuators, which then take billions of iterations. */ + if (ScriptController::GetOpsTillSuspend() < -1000000) { + /* See below for explanation. The extra pop is the return value. */ + sq_pop(vm, nparam + 4); + + ScriptObject::SetAllowDoCommand(backup_allow); + return sq_throwerror(vm, "excessive CPU usage in valuator function"); + } + /* Was something changed? */ if (previous_modification_count != this->modifications) { /* See below for explanation. The extra pop is the return value. */ From 5ac736ec00c770b37948ef581a66c571802b3ee7 Mon Sep 17 00:00:00 2001 From: smatz Date: Tue, 31 May 2016 19:33:33 +0000 Subject: [PATCH 6/6] (svn r27595) -Fix: prevent GCC 6 over-optimization --- config.lib | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config.lib b/config.lib index 0259739eb4..021f95cb21 100644 --- a/config.lib +++ b/config.lib @@ -1401,6 +1401,12 @@ make_compiler_cflags() { flags="$flags -Wno-free-nonheap-object" fi + if [ $cc_version -ge 60 ]; then + # -flifetime-dse=2 (default since GCC 6) doesn't play + # well with our custom pool item allocator + cxxflags="$cxxflags -flifetime-dse=1" + fi + if [ "$enable_lto" != "0" ]; then # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}' has_lto=`$1 -dumpspecs | grep '\%{flto'`