Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

[preview-12] EntityCommandBuffer not properly dealing with zero size components

Discussion in 'Entity Component System' started by MartijnGG, Sep 5, 2018.

  1. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    I've had an issue where some of my components where magically being zero'd, which I think I've tracked down to a problem in the EntityCommandBuffer.AddComponent.

    Internally, this uses UnsafeUtility.SizeOf<T>(); to figure out how much data needs to be copied over, while the AddBuffer and EntityManager.AddComponent commands have moved over to using TypeInfo.SizeInChunk.

    Changing the code to use SizeInChunk instead of SizeOf has fixed my issues.
     
  2. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    Sorry for the bump, I just want to make sure this has been seen as it is super painful to run into.
     
  3. dartriminis

    dartriminis

    Joined:
    Feb 3, 2017
    Posts:
    157
    Good find! This was actually causing my Unity to crash every time I exited play mode.Changing EntityCommandBuffer.
    AddEntityComponentCommand() to use TypeInfo.SizeInChunk fixed that crash.
     
  4. mike_acton

    mike_acton

    Unity Technologies

    Joined:
    Nov 21, 2017
    Posts:
    110
    Thanks. This will be fixed in newer version.
     
    MartijnGG and jamiebrynes like this.
  5. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    Thank you very much for fixing this in preview 13.

    However, sadly, it seems this is broken again in preview 14.
    The change was reverted with a note

    // NOTE: This has to be sizeof not TypeManager.SizeInChunk since we use UnsafeUtility.CopyStructureToPtr
    // even on zero size components.

    Which is correct. However since the componentSize passed into the header, is also using the same variable, its now storing this as 1 as well. Instead of the 0 it should be.
     
    Last edited: Sep 23, 2018
    jamiebrynes likes this.
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You are right. Apologies, surprised our test rig didn't detect this for some reason. We will get this fixed for real in next release.
     
    jamiebrynes and dartriminis like this.
  7. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    Thank you very much for the quick reply! I'll look forward to the fix.