diff --git a/config.lib b/config.lib index b6bb0e5d6a..6e8faf67c4 100644 --- a/config.lib +++ b/config.lib @@ -1428,6 +1428,12 @@ make_compiler_cflags() { CFLAGS="$CFLAGS -DCUSTOM_ALLOCATOR" 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'` diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 3d99973e4f..1207d02168 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -665,7 +665,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(); } diff --git a/src/economy.cpp b/src/economy.cpp index e0d546ada3..b503ce7241 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1328,7 +1328,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); } /** @@ -1662,6 +1663,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/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index a7caa7b953..214fe2b502 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -438,29 +438,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); } }; @@ -512,7 +517,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 */ @@ -520,8 +525,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); } 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. */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 4f233bff30..1e82f1adf0 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -283,7 +283,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. } @@ -834,6 +834,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()) { @@ -2493,6 +2494,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);