Hi All, Is this a limitation of Burst or a bug? I have a simple static readonly array, which all compiles fine with Burst (there are several arrays) until I add the single static readonly field angleThreshold and then it fails to compile with Burst. Anyone seen this before?
private static float angleThreshold = math.cos(math.radians(THRESHOLD));
private static readonly int2[] offset3x3 = new int2[]
{
new(-1, -1), new(0, -1), new(1, -1),
new(-1, 0), new(0, 0), new(1, 0),
new(-1, 1), new(0, 1), new(1, 1)
};
The strange thing is the Burst error refers to the array, not the recently added field? :
Burst error BC1361: The static readonly array field Unity.Mathematics.int2[] Bodyclock.Framework.Graph::offset3x3
of type Bodyclock.Framework.Graph is not supported by Burst`.
Hi @Bodyclock,
So, the issue here is that Burst tries evaluate all static fields (and static constructors) at compile-time for a given class. If one field fails, none of them get promoted to compile-time constants and only compile-time constant (readonly
) arrays are allowed in Bursted code (See Static read-only fields and static constructor support | Burst | 1.8.18).
The thing actually making compile time evaluation fail here, is actually the math.cos
call and that’s because we’ve found that - for various - reasons trying to evaluate it at compile time is non-deterministic both between different platforms and between the result you’d get if you called the method in Burst compiled code. So we don’t allow them in static initializers.
All of this is of course quite confusing and something I’ve been wanting to improve for a while. So hopefully in the future we can improve the error messages, so you’ll get more information about why stuff like this fails:)
If you separate out angleThreshold
into a different class/struct then it shouldn’t interfere with offset3x3
1 Like
Thanks Marco, makes sense. As you say, the error trail is a little hard to track. 