summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-17 04:23:03 +0000
committerrubidium <rubidium@openttd.org>2007-09-17 04:23:03 +0000
commitf41c8ab3aa532845b480589be09fb630c957a40e (patch)
tree7b1861fb2f716b857d3f3e5cc617f04cc8d36524 /src/train_cmd.cpp
parent4e130204aef7ee8d6b13f4928589dc5e408edaf8 (diff)
downloadopenttd-f41c8ab3aa532845b480589be09fb630c957a40e.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/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 188695148..f142389f7 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -514,12 +514,12 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
const RailVehicleInfo *rvi = RailVehInfo(engine);
CommandCost value((GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
- uint num_vehicles = 1 + CountArticulatedParts(engine);
+ uint num_vehicles = 1 + CountArticulatedParts(engine, false);
if (!(flags & DC_QUERY_COST)) {
- /* Allow for the wagon and the articulated parts. */
- Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * num_vehicles);
- memset(vl, 0, sizeof(*vl) * num_vehicles);
+ /* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
+ Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
+ memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
if (!Vehicle::AllocateList(vl, num_vehicles))
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
@@ -682,12 +682,12 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
uint num_vehicles =
(rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) +
- CountArticulatedParts(p1);
+ CountArticulatedParts(p1, false);
if (!(flags & DC_QUERY_COST)) {
- /* Allow for the dual-heads and the articulated parts. */
- Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * num_vehicles);
- memset(vl, 0, sizeof(*vl) * num_vehicles);
+ /* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */
+ Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
+ memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
if (!Vehicle::AllocateList(vl, num_vehicles))
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);