Tracerestrict: Fix non-deterministic use of _sorted_cargo_specs

This commit is contained in:
Jonathan G Rennison
2019-08-19 20:02:24 +01:00
parent 0d2277211c
commit ccdc75e2bf
2 changed files with 9 additions and 2 deletions

View File

@@ -53,6 +53,13 @@ uint8 FindFirstBit(uint32 x)
return pos;
}
uint8 FindFirstBit64(uint64 x)
{
if (x == 0) return 0;
if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit(x);
return FindFirstBit(x >> 32) + 32;
}
/**
* Search the last set bit in a 64 bit variable.
*

View File

@@ -630,8 +630,8 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp
break;
case TRVT_CARGO_ID:
assert(_sorted_standard_cargo_specs_size > 0);
SetTraceRestrictValue(item, _sorted_cargo_specs[0]->Index());
assert(_standard_cargo_mask != 0);
SetTraceRestrictValue(item, FindFirstBit64(_standard_cargo_mask));
SetTraceRestrictAuxField(item, 0);
break;