Search Unity

Bug NullReferenceException when compiling?

Discussion in 'Burst' started by ThompZon, Apr 17, 2021.

  1. ThompZon

    ThompZon

    Joined:
    Sep 12, 2018
    Posts:
    7
    I get Burst error BC0101 when compiling my job.

    The job and component used by job:

    basically it gets a NPE on line1 in the job execute, even if I change it to: "int2 pos = int2.zero;"
    I have no idea on how to fix it. Basically
    Burst bug?
    Or user error? (I.E. I've done something stupid?)

    Unity version: 2021.1.3f1
    BurstVersion: 1.4.7
    Jobs: 0.8.0-previws.23

    Code (CSharp):
    1.  
    2. public unsafe struct NoiceComponent : IComponentData
    3. {
    4.     public fixed float noiceMatrix[Constants.CHUNK_SIZE_BLOCKS * Constants.CHUNK_SIZE_BLOCKS];
    5. }
    6.  
    7.     [BurstCompile(CompileSynchronously = true)]
    8.     public struct NoiceGenerationJobFor : IJobParallelFor
    9.     {
    10.         [ReadOnly]
    11.         public NativeArray<int2> chunksToGenerateFor;
    12.         [ReadOnly]
    13.         public NoiceSettings noiceSettings;
    14.  
    15.         [WriteOnly]
    16.         public NativeArray<NoiceComponent> result;
    17.         public void Execute(int index)
    18.         {
    19.             int2 pos = chunksToGenerateFor[index];
    20.             float[,] noice = NoiceGenerator.PerlinGenerator(CHUNK_SIZE_BLOCKS, noiceSettings, new Vector2(pos.x, pos.y));
    21.             NoiceComponent component = new NoiceComponent(){
    22.                 dimensionSize = CHUNK_SIZE_BLOCKS,
    23.             };
    24.             unsafe
    25.             {
    26.                 for(int y = 0; y < CHUNK_SIZE_BLOCKS; y++)
    27.                 {
    28.                     for(int x = 0; x < CHUNK_SIZE_BLOCKS; x++)
    29.                     {
    30.                         component.noiceMatrix[y * CHUNK_SIZE_BLOCKS + x] = noice[x, y];
    31.                     }
    32.                 }
    33.             }
    34.             result[index] = component;
    35.         }
    36.     }
    37.  
    Code (Boo):
    1.  
    2. C:\Users\ThompZon\Unity\ProceduralDotsMeshGenerationTest\Assets\Scripts\MapGeneration\Noice\NoiceGenerationJob.cs(66,25): Burst error BC0101: Unexpected error while processing function `NoiceGenerationJob.NoiceGenerationJobFor.Execute(NoiceGenerationJob.NoiceGenerationJobFor* this, int index)`: System.NullReferenceException: Object reference not set to an instance of an object
    3.   at Burst.Compiler.IL.Syntax.ILBuilder.ResolveThisCall (Mono.Cecil.TypeReference thisType, Mono.Cecil.MethodReference methodReference) [0x00035] in <3e87bd30b339441eaceba44e8d9c979f>:0
    4.   at Burst.Compiler.IL.Syntax.ILBuilder.Call (Mono.Cecil.Cil.Instruction inst, Mono.Cecil.MethodReference methodReference, Burst.Compiler.IL.Syntax.ILExpression thisArgument) [0x000c7] in <3e87bd30b339441eaceba44e8d9c979f>:0
    5.   at Burst.Compiler.IL.Syntax.ILBuilder.ProcessInstruction (Mono.Cecil.Cil.Instruction inst) [0x003d6] in <3e87bd30b339441eaceba44e8d9c979f>:0
    6.   at Burst.Compiler.IL.Syntax.ILBuilder.ProcessInstructions () [0x000da] in <3e87bd30b339441eaceba44e8d9c979f>:0
    7.   at Burst.Compiler.IL.Syntax.ILBuilder.ProcessFunctionBody () [0x00090] in <3e87bd30b339441eaceba44e8d9c979f>:0
    8.   at Burst.Compiler.IL.Syntax.ILBuilder.CreateFunctionFromRef (Burst.Compiler.IL.Syntax.ILFunctionReference funcRef) [0x000fa] in <3e87bd30b339441eaceba44e8d9c979f>:0
    9.   at Burst.Compiler.IL.Syntax.ILBuilder.VisitPendingFunctionReferences () [0x000b2] in <3e87bd30b339441eaceba44e8d9c979f>:0
    10.  at NoiceGenerationJob.NoiceGenerationJobFor.Execute(NoiceGenerationJob.NoiceGenerationJobFor* this, int index) (at C:\Users\ThompZon\Unity\ProceduralDotsMeshGenerationTest\Assets\Scripts\MapGeneration\Noice\NoiceGenerationJob.cs:57)
    11.  at Unity.Jobs.IJobParallelForExtensions.ParallelForJobStruct`1<NoiceGenerationJob.NoiceGenerationJobFor>.Execute(ref NoiceGenerationJob.NoiceGenerationJobFor jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex)
    12. While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<NoiceGenerationJob/NoiceGenerationJobFor>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
    13. at C:\Users\ThompZon\Unity\ProceduralDotsMeshGenerationTest\Assets\Scripts\MapGeneration\Noice\NoiceGenerationJob.cs:line 66
    14.  
     
  2. sheredom

    sheredom

    Unity Technologies

    Joined:
    Jul 15, 2019
    Posts:
    300
    I can repro this. I think it is something to do with the float[,] return, which Burst doesn't support.

    But I'll try and get Burst to output a better compiler message for this issue either way!
     
  3. sheredom

    sheredom

    Unity Technologies

    Joined:
    Jul 15, 2019
    Posts:
    300
    I can confirm this is indeed an issue with the multi-dimensional array - Burst does not support these. I'll do a fix and get it into a patch release of 1.5 that will give an actual error message for this though!
     
  4. ThompZon

    ThompZon

    Joined:
    Sep 12, 2018
    Posts:
    7
    Yep, I understood that the day after or so, tried to edit with more details, but were not allowed to (probably because too new account or something).

    Better error message is the "solution" for this, sounds good :)
     
    sheredom likes this.