Search Unity

Burst error when writing component with generics

Discussion in 'Burst' started by GilCat, Apr 5, 2019.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Does burst support writing on components with generics?
    I'm having an error only when writing on those.
    Unexpected error while processing instruction `IL_0007: stfld T GenericComponent`1<System.Single>::Value args(IL_0001, IL_0002)`. Reason: Object reference not set to an instance of an object

    at TestSystem.MyWriteJob.Execute(TestSystem.MyWriteJob* this, ref GenericComponent`1<float> c0)

    Here is some code to reproduce it:
    Code (CSharp):
    1. public struct GenericComponent<T> : IComponentData {
    2.   public T Value;
    3. }
    4.  
    5. public class TestSystem : JobComponentSystem
    6. {
    7.   [BurstCompile]
    8.   struct MyWriteJob : IJobProcessComponentData<GenericComponent<float>> {
    9.  
    10.     public void Execute([WriteOnly]ref GenericComponent<float> c0) {
    11.       c0.Value = 10f;
    12.     }
    13.   }
    14.  
    15.   [BurstCompile]
    16.   struct MyReadJob : IJobProcessComponentData<GenericComponent<float>, Translation> {
    17.  
    18.     public void Execute([ReadOnly]ref GenericComponent<float> c0, [WriteOnly]ref Translation c1) {
    19.       c1.Value = c0.Value;
    20.     }
    21.   }
    22.  
    23.   protected override JobHandle OnUpdate(JobHandle inputDeps) {
    24.     inputDeps = new MyWriteJob().Schedule(this, inputDeps);
    25.     inputDeps = new MyReadJob().Schedule(this, inputDeps);
    26.     return inputDeps;
    27.   }
    28. }
    29.  
    30. public class ScopeBootstrap {
    31.   [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    32.   public static void InitializeAfterScene() {
    33.     var em = World.Active.GetOrCreateManager<EntityManager>();
    34.     var entity = em.CreateEntity();
    35.     em.AddComponentData(entity, new LocalToWorld { Value = float4x4.identity });
    36.     em.AddComponentData(entity, new Translation());
    37.     em.AddComponentData(entity, new GenericComponent<float>());
    38.   }
    39. }
    40.  
     
    yc960 likes this.
  2. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    418
    It should. Which version of burst are you using?
     
  3. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    It happens on Burst 1.0.0 preview 9
    Sorry i forgot to mention the version. I've also tried in all 1.0.0 versions in case it was some regression
     
  4. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    418
    Thanks we will have a look (though we will likely be able to fix it in a patch version of 1.0 stable likely)
     
    GilCat likes this.
  5. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    418
    Errata, I thought it was another issue. For this one we will fix it before 1.0 stable.
     
    Timboc, FROS7 and GilCat like this.