[burst 1.0-preview.12] Structlayout Explicit Crashes The Whole Editor On Compilation

When using Burst compilation and this following struct inside of a ComponentData/Job, my whole editor crashes. Removing the struct layout fixes this, but I thought that LayoutKind.Explicit was supported for Burst?

        [StructLayout(LayoutKind.Explicit)]
        public struct UnionValue
        {
            [FieldOffset(0)]
            public float Min;
            [FieldOffset(4)]
            public float Max;

            [FieldOffset(0)]
            public uint Property;
      }

What version of Unity are you running? I’m using the 2019.1 RC and I only have access to preview 10. Are you using the staging registry still?

Yep, we need to know the version first before investigating. If you are not on latest (preview.10) I encourage you to test it first. Layout should work, we have unit tests covering it, but you could have hit an issue.

oops sorry, it is in the title, missed that…

So when you say it crashes, it crashes also the inspector when you want to compile this method or it crashes when you run the job?

Could you log an issue for this and report the case number back here, we don’t really have enough information to go on from the struct alone.

I’m on the latest of the latest ( 2019.1.0f1, Burst 1.0.0-preview.12 )

Took me a while to pin down the location because it would seem to crash at random during runtime. I noticed that disabling jobs compilation fixed this, then after an hours of debugging I noticed that if I compiled some specific jobs ( the ones that used my explicit layout struct ) through the inspector I would get the same instant editor crash ( the whole editor )

Sorry I couldn’t upload my project, it’s way too complex at this moment, but here’s the case number: (Case 1145230)

If this isn’t enough I could take some time off in the following weeks to see if I can make a simple bug reproduction project.

Could you explain how this struct is used? How it is embedded and accessed through? (In the NativeArray? A ComponentData?..)

We can only fix this issue if we are able to reproduce it, so it would help a lot if you could try to isolate what is making the whole compiler crashing (this is pretty rare) and send us a small repro. We have been fixing an issue with the sizeof of struct with explicit layout which could be wrong depending on the cases and it will be available in 1.0.0-preview.13 hopefully this Monday, but I don’t think it is related to your issue

I replied to Matas Vaidelauskas with an isolated script that reproduces this issue.
I’ve also attached it to this post.

To cause the crash it’s easy as:

  • Jobs > Burst > Open Inspector…
  • Select Test.TestTargetDistanceJon
  • Click Refresh Disassembly
  • Crash

Another other way to cause the crash would would be running the script in the scene, but I imagine it’s the compilation part that crashes.

4426096–404014–Burst-structlayout-bug-reproduction.zip (17.3 KB)

1 Like

Just tested it with 1.0.0-preview.13, same crash

Thanks, we made a fix, it should go out for 1.0.0-preview.14 hopefully today (or final 1.0.0 tomorrow)

3 Likes

I found that the burst crashes the editor when using readonly collections and writing to them within a bursted IJobChunk.
I know it’s wrong doing that ( I juste forgot to modify them after a change ), but I think it should show an error message instead of crashing or freezing the editor.