Search Unity

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

Discussion in 'Burst' started by Xerioz, Apr 11, 2019.

  1. Xerioz

    Xerioz

    Joined:
    Aug 13, 2013
    Posts:
    104
    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?

    Code (CSharp):
    1.  
    2.         [StructLayout(LayoutKind.Explicit)]
    3.         public struct UnionValue
    4.         {
    5.             [FieldOffset(0)]
    6.             public float Min;
    7.             [FieldOffset(4)]
    8.             public float Max;
    9.  
    10.             [FieldOffset(0)]
    11.             public uint Property;
    12.       }
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,267
    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?
     
  3. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    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.
     
  4. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    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?
     
  5. Lee_Hammerton

    Lee_Hammerton

    Unity Technologies

    Joined:
    Jul 26, 2018
    Posts:
    118
    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.
     
  6. Xerioz

    Xerioz

    Joined:
    Aug 13, 2013
    Posts:
    104
    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.
     
  7. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Could you explain how this struct is used? How it is embedded and accessed through? (In the NativeArray? A ComponentData?...)
     
  8. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    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
     
  9. Xerioz

    Xerioz

    Joined:
    Aug 13, 2013
    Posts:
    104
    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:
    1. Jobs > Burst > Open Inspector...
    2. Select Test.TestTargetDistanceJon
    3. Click Refresh Disassembly
    4. 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.
     

    Attached Files:

    June1111 likes this.
  10. Xerioz

    Xerioz

    Joined:
    Aug 13, 2013
    Posts:
    104
    Just tested it with 1.0.0-preview.13, same crash
     
  11. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Thanks, we made a fix, it should go out for 1.0.0-preview.14 hopefully today (or final 1.0.0 tomorrow)
     
    FROS7, Xerioz and June1111 like this.
  12. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    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.