(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.

This commit is contained in:
rubidium
2007-09-17 04:23:03 +00:00
parent f3491cb062
commit 257fdb38e6
5 changed files with 24 additions and 17 deletions

View File

@@ -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;