diff options
author | rubidium <rubidium@openttd.org> | 2007-09-17 04:23:03 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-09-17 04:23:03 +0000 |
commit | 257fdb38e6dde17a1d3546d83c67679ccba7160b (patch) | |
tree | 7b1861fb2f716b857d3f3e5cc617f04cc8d36524 /src/articulated_vehicles.cpp | |
parent | f3491cb062a5854b6a8c713520c6af3ca2b36335 (diff) | |
download | openttd-257fdb38e6dde17a1d3546d83c67679ccba7160b.tar.xz |
(svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
Diffstat (limited to 'src/articulated_vehicles.cpp')
-rw-r--r-- | src/articulated_vehicles.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 0f6aa8954..0f9fe9cc1 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -15,16 +15,24 @@ #include "newgrf_engine.h" -uint CountArticulatedParts(EngineID engine_type) +uint CountArticulatedParts(EngineID engine_type, bool purchase_window) { if (!HASBIT(EngInfo(engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return 0; + Vehicle *v = NULL;; + if (!purchase_window) { + v = new InvalidVehicle(); + v->engine_type = engine_type; + } + uint i; for (i = 1; i < MAX_UVALUE(EngineID); i++) { - uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine_type, NULL); + uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine_type, v); if (callback == CALLBACK_FAILED || callback == 0xFF) break; } + delete v; + return i - 1; } @@ -42,7 +50,6 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type) /* Attempt to use pre-allocated vehicles until they run out. This can happen * if the callback returns different values depending on the cargo type. */ u->SetNext(vl[i]); - if (u->Next() == NULL) u->SetNext(new InvalidVehicle()); if (u->Next() == NULL) return; Vehicle *previous = u; |