Search Unity

Static readonly structs in Burst not working as expected

Discussion in 'Burst' started by threedots1, Dec 13, 2019.

  1. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    I have a job which refuses to Burst compile while referencing static readonly float3s.

    There is no output to the console indicating compilation has failed, however digging through the Editor.log shows this error when it attempts to compile the code.

    If I replace the reference to the static readonly with a new declaration, for eg.
    Code (CSharp):
    1. new float3(5.8e-6f, 1.35e-5f, 3.31e-5f)
    the compiler works correctly.

    Are static readonly structs not supported in Burst?
    I have no problem accessing static readonly arrays.
     
  2. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Could you report this via Unity bug reporting so we can reprocute it?
     
  3. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Unexpected exception while logging System.ArgumentException: The output byte buffer is too small to contain the encoded data, encoding 'US-ASCII' fallback 'System.Text.EncoderReplacementFallback'.


    This error is being fixed.

    For the issue with readonly struct, we need a simple repro to have a look at it.
     
  4. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    Tried putting together a simple repro this morning but it worked fine, so there must be something about the particular structure of my current project code that is breaking it.

    I'll try breaking it again when I get a little time and I'll post a bug report.

    Cheers xoofx
     
  5. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    Finally managed to break it!
    Case No: 1205415

    It looks like it is caused by having a static readonly Dictionary initialised inside the same struct as where the static readonly float3 is contained. The Dictionary isn't being used for Burst of course, it's just in a struct where I was storing some constants.

    Also managed to get an error out of Burst.
     
  6. threedots1

    threedots1

    Joined:
    Oct 9, 2014
    Posts:
    88
    I'm guessing that the Burst compiler tries to initialise the entire struct which explains bombing out on the Dictionary. Strangely though there was no error message printed in my project but it worked fine in the simpler repro though, hopefully that's fixed now as you said.
     
  7. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Yes, we don't support mixed initialization of managed objects and non managed within static readonly. They all end-up in the same static constructor. We have fixed the issue with the buffer too small.