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/train_cmd.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/train_cmd.cpp')
-rw-r--r-- | src/train_cmd.cpp | 16 |
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); |