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.

Burst Compile Error while reading from SharedComponentDataArray

Discussion in 'Burst' started by yc960, Jul 13, 2018.

  1. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Reading from SharedComponentDataArray in a burst compiled IJobParallelFor job trigger following error in editor:
    "
    C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\Iterators\SharedComponentDataArray.cs(38,13): error: Unable to get field because it is a class type

    While processing function `!0 Unity.Entities.SharedComponentDataArray`1<T>::get_Item(System.Int32)`

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<LOTE.Utility.OffsetSharedData`1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

    Compiler exception: System.InvalidOperationException: Unable to get field because it is a class type
    at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0001b] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
    "

    "
    C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: The given key was not present in the dictionary.

    While processing function `T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)`

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<LOTE.Utility.OffsetSharedData`1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

    Compiler exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <f826c2584fc94ec19a48a6576640bdc5>:0
    at Burst.Compiler.IL.ILVisitor.GetStructLayout (Mono.Cecil.TypeReference structType) [0x0001e] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0003b] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
    "

    "
    C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: Error while compiling parameter `this` for function `!0 System.Collections.Generic.List`1<System.Object>::get_Item(System.Int32)`: The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst

    While processing function `T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)`

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<LOTE.Utility.OffsetSharedData`1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

    Compiler exception: System.NotSupportedException: The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet`1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x002bc] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet`1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x0023a] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x00006] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileFunctionArgument (Burst.Backend.FunctionBuilder functionBuilder, Burst.Compiler.IL.Syntax.ILFunction function, Burst.Compiler.IL.Syntax.ParameterBinding paramBinding) [0x00038] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVerifier.CompileFunctionArgument (Burst.Backend.FunctionBuilder functionBuilder, Burst.Compiler.IL.Syntax.ILFunction function, Burst.Compiler.IL.Syntax.ParameterBinding paramBinding) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
    "

    "
    C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: The opcode instruction `IL_0021: unbox.any T args(IL_001c)` is not supported by burst

    While processing function `T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)`

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<LOTE.Utility.OffsetSharedData`1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

    Compiler exception: System.NotSupportedException: The opcode instruction `IL_0021: unbox.any T args(IL_001c)` is not supported by burst
    at Burst.Compiler.IL.ILVisitor.NotSupported (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0016b] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00498] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
    "

    (0,0): error: The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst

    While processing function `!0 System.Collections.Generic.List`1<System.Object>::get_Item(System.Int32)`

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<LOTE.Utility.OffsetSharedData`1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

    Compiler exception: System.NotSupportedException: The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet`1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x002bc] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x00006] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference resolveGenerics, Burst.Compiler.IL.Syntax.TypeUsage usage) [0x00014] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.GetStructLayout (Mono.Cecil.TypeReference structType) [0x00015] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0003b] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
    at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0

    "

    Note that none of them show up when not using burst compile.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,449
    Unable to get field because it is a class type


    You can't use classes in jobs and you seem to be using a List<T>

    The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst
     
  3. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    The isharedcomponent struct simply contain an enum, so i suspect the list is related to sharecomponentdataarray. Since there is no error when burst compile is not on.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,449
    can you post your job?
     
  5. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Code (CSharp):
    1.     public struct CopySharedData<T> : IJobParallelFor where T : struct, ISharedComponentData
    2.     {
    3.         [ReadOnly] public SharedComponentDataArray<T> Source;
    4.         [WriteOnly] public NativeArray<T> Results;
    5.  
    6.  
    7.         public void Execute(int index)
    8.         {
    9.             Results[index] = Source[index];
    10.         }
    11.     }
     
  6. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,108
    You have to disable the parallel for write restriction
     
  7. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    It has nothing to do with parallel for write restriction, I am not doing anything funny with index. And it works fine without burst.
     
  8. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,108
    sorry - did not read this properly. You already narrowed it to the reading part and I do not know the reason...
     
  9. mike_acton

    mike_acton

    Unity Technologies

    Joined:
    Nov 21, 2017
    Posts:
    110
    SharedComponentData are managed data at the moment. They can't be used from burst compiled jobs.