NullReferenceException when compiling?

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

public unsafe struct NoiceComponent : IComponentData
{
    public fixed float noiceMatrix[Constants.CHUNK_SIZE_BLOCKS * Constants.CHUNK_SIZE_BLOCKS];
}

    [BurstCompile(CompileSynchronously = true)]
    public struct NoiceGenerationJobFor : IJobParallelFor
    {
        [ReadOnly]
        public NativeArray<int2> chunksToGenerateFor;
        [ReadOnly]
        public NoiceSettings noiceSettings;

        [WriteOnly]
        public NativeArray<NoiceComponent> result;
        public void Execute(int index)
        {
            int2 pos = chunksToGenerateFor[index];
            float[,] noice = NoiceGenerator.PerlinGenerator(CHUNK_SIZE_BLOCKS, noiceSettings, new Vector2(pos.x, pos.y));
            NoiceComponent component = new NoiceComponent(){
                dimensionSize = CHUNK_SIZE_BLOCKS,
            };
            unsafe
            {
                for(int y = 0; y < CHUNK_SIZE_BLOCKS; y++)
                {
                    for(int x = 0; x < CHUNK_SIZE_BLOCKS; x++)
                    {
                        component.noiceMatrix[y * CHUNK_SIZE_BLOCKS + x] = noice[x, y];
                    }
                }
            }
            result[index] = component;
        }
    }
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
  at Burst.Compiler.IL.Syntax.ILBuilder.ResolveThisCall (Mono.Cecil.TypeReference thisType, Mono.Cecil.MethodReference methodReference) [0x00035] in <3e87bd30b339441eaceba44e8d9c979f>:0 
  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 
  at Burst.Compiler.IL.Syntax.ILBuilder.ProcessInstruction (Mono.Cecil.Cil.Instruction inst) [0x003d6] in <3e87bd30b339441eaceba44e8d9c979f>:0 
  at Burst.Compiler.IL.Syntax.ILBuilder.ProcessInstructions () [0x000da] in <3e87bd30b339441eaceba44e8d9c979f>:0 
  at Burst.Compiler.IL.Syntax.ILBuilder.ProcessFunctionBody () [0x00090] in <3e87bd30b339441eaceba44e8d9c979f>:0 
  at Burst.Compiler.IL.Syntax.ILBuilder.CreateFunctionFromRef (Burst.Compiler.IL.Syntax.ILFunctionReference funcRef) [0x000fa] in <3e87bd30b339441eaceba44e8d9c979f>:0 
  at Burst.Compiler.IL.Syntax.ILBuilder.VisitPendingFunctionReferences () [0x000b2] in <3e87bd30b339441eaceba44e8d9c979f>:0 
 at NoiceGenerationJob.NoiceGenerationJobFor.Execute(NoiceGenerationJob.NoiceGenerationJobFor* this, int index) (at C:\Users\ThompZon\Unity\ProceduralDotsMeshGenerationTest\Assets\Scripts\MapGeneration\Noice\NoiceGenerationJob.cs:57)
 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)
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)
at C:\Users\ThompZon\Unity\ProceduralDotsMeshGenerationTest\Assets\Scripts\MapGeneration\Noice\NoiceGenerationJob.cs:line 66

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!

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!

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 :slight_smile:

1 Like