diff src/roadveh_cmd.cpp @ 7595:bb5f187ff5a7 draft

(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.
author rubidium <rubidium@openttd.org>
date Mon, 17 Sep 2007 04:23:03 +0000
parents 200598005e58
children 610b2a5d634a
line wrap: on
line diff
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -179,11 +179,11 @@
 
 	if (HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) != HASBIT(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_DEPOT_WRONG_DEPOT_TYPE);
 
-	uint num_vehicles = 1 + CountArticulatedParts(p1);
+	uint num_vehicles = 1 + CountArticulatedParts(p1, false);
 
-	/* Allow for the front and the articulated parts. */
-	Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * num_vehicles);
-	memset(vl, 0, sizeof(*vl) * num_vehicles);
+	/* Allow for the front 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);