Search Unity

[0.0.12-preview.32] NativeArray is giving me a StructLayout size error

Discussion in 'Entity Component System' started by Xerioz, May 17, 2019.

  1. Xerioz

    Xerioz

    Joined:
    Aug 13, 2013
    Posts:
    104
    Started getting this error on creation of World, no idea what it refers to.

    Code (CSharp):
    1. ArgumentException: All component types containing pointers must use a [StructLayout(LayoutKind.Explicit, Size = <multiple of 8>)] attribute such that the type's size is the same on both 32-bit and 64-bit platforms. Type 'Unity.Collections.NativeArray`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is missing a this attribute due to pointer field 'm_Buffer'
    I only have one StructLayout in my code, and even removing it doesn't help.

    Any ideas where this could be coming from?

    I'm using latest 2019.1.3f1 unity version
     
  2. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    Marking this answer as deprecated cause of the following post by Joachim.

    So I had this problem too but this is on my old deprecated code which I eventually switched just recently.

    If you have a struct which contains pointer based elements, in my case:

    Code (CSharp):
    1. public struct SomeStruct : ISharedComponentData {
    2.   public NativeArray<int> Values;
    3. }
    You'll have to include the StructLayout attribute and define the size of that struct. For me, I eventually got rid of the ISharedComponentData's with the NativeArray and replaced it with IBufferElementData.

    I'd start looking at structs which use pointer based structures/values and go from there.
     
    Last edited: May 17, 2019
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    This is a regression in p32, i suggest downgrading to p31 for the time being.
     
    FROS7, Xerioz and psuong like this.