Why static FixedString can't be Burstable and static primitive can?

Hello,

I’m working on logs for our game, and during my test, I found that statics FixedStringXBytes throw errors when using them inside a [BurstCompile] method (we’re using DOTS).

But the error only occurs when using a static FixedStringXBytes and not a local one, nor a static primitive type like int. So, how Burst does work for static non-primitive types and why does not this work?

[BurstCompile]
public partial struct Test : ISystem
{
    public static readonly FixedString32Bytes StringTest = "Does not work";
    public static readonly int IntTest = 1;

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        FixedString32Bytes stringTest = "Does work";
        Debug.Log($"This is ok {stringTest}");
        
        Debug.Log($"This is ok {IntTest}");
        
        /* Burst error BC0102: Unexpected internal compiler error while
         * processing function `IL_0041: ldflda Unity.Collections.FixedString32Bytes
         * Simulation.ECS.Systems.Test::StringTest`: System.NullReferenceException:
         * Object reference not set to an instance of an object
         * at Burst.Compiler.IL.Syntax.ILInstruction+ArgumentList.get_Item
         */
        Debug.Log($"This throws an error {StringTest}");
    }
}

Thank you

Hi @DarkRewar ,

Thank you for bringing the issue to our attention. I was able to reproduce it locally and have logged and bug.

Still happens with exact scenario. I believe it is because struct stores bytes in pointers. Burst could actually create a temporary FixedString while compiling. Also with this approach the same trick can be applied to string as well. Creating FixedString from string could be possible. This way, strings will be supported.

Hi @Wilhelm_LAS - please could you post your repro code?

Because we did fix the above bug a while ago - back in Burst 1.8.20 - so it shouldn’t still happen, at least not in that exact scenario.