NativeArray<float> vals = new NativeArray<float>(8, Allocator.Temp);
vals[0] = _voxels[xi + yi * SizeX + zi * SizeX * SizeY];
vals[1] = _voxels[(xi + 1) + yi * SizeX + zi * SizeX * SizeY];
vals[2] = _voxels[(xi + 1) + (yi + 1) * SizeX + zi * SizeX * SizeY];
vals[3] = _voxels[xi + (yi + 1) * SizeX + zi * SizeX * SizeY];
vals[4] = _voxels[xi + yi * SizeX + (zi + 1) * SizeX * SizeY];
vals[5] = _voxels[(xi + 1) + yi * SizeX + (zi + 1) * SizeX * SizeY];
vals[6] = _voxels[(xi + 1) + (yi + 1) * SizeX + (zi + 1) * SizeX * SizeY];
vals[7] = _voxels[xi + (yi + 1) * SizeX + (zi + 1) * SizeX * SizeY];
Unexpected exception Burst.Compiler.IL.CompilerException: Unexpected exception —> Burst.Compiler.IL.CompilerException: Error while processing function System.Void Unity.Collections.LowLevel.Unsafe.DisposeSentinel::Create(Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle&,Unity.Collections.LowLevel.Unsafe.DisposeSentinel&,System.Int32,Unity.Collections.Allocator)
—> Burst.Compiler.IL.CompilerException: Unexpected error while processing IL_0056: ldnull
at C:\buildslave\unity\build\Runtime\Export\NativeArray\DisposeSentinel.cs(62,17) —> System.NotSupportedException: Using managed null
is not supported by burst
at Burst.Compiler.IL.ILVisitor.NotSupported (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0016b] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00523] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00018] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.Compile (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0001e] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.ProcessBlock (Burst.Compiler.IL.Syntax.ILBlock block) [0x0009a] in <37bebafd236f4ccd943dc039a926a017>:0
— End of inner exception stack trace —
at Burst.Compiler.IL.ILVisitor.ProcessBlock (Burst.Compiler.IL.Syntax.ILBlock block) [0x000e9] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.ProcessBlocks () [0x0002e] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.ProcessFunctionBody (Burst.Compiler.IL.Syntax.ILFunction function) [0x00103] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.VisitPendingFunctions () [0x0000e] in <37bebafd236f4ccd943dc039a926a017>:0
— End of inner exception stack trace —
at Burst.Compiler.IL.ILVisitor.VisitPendingFunctions () [0x00033] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.VisitEntryPointFunction (Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00066] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVisitor.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x0001a] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILVerifier.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00000] in <37bebafd236f4ccd943dc039a926a017>:0
— End of inner exception stack trace —
at Burst.Compiler.IL.ILVerifier.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x0001f] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.ILHash.CompileHash (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00000] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.NativeCompiler.ComputeHash () [0x000ea] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.Jit.JitCompiler.CompileMethod (Mono.Cecil.MethodReference methodReference, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x000aa] in <37bebafd236f4ccd943dc039a926a017>:0
at Burst.Compiler.IL.Jit.JitCompilerService.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job) [0x002b2] in <37bebafd236f4ccd943dc039a926a017>:0
While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
Is there nay sort of work around for this? I thought that in Unity 2018.3, that this would be fixed? (I am running 2019 ALPHA but I tested it with the Unity 2018.3 BETA too)
1 Like
Are you trying to run the above code in a Job? If so, allocating a native array isn’t supported in jobs, it must be done on the main thread. Everything else should work fine in a job.
5argon
November 18, 2018, 3:35am
3
UT should have put “Coming Soon” section in the docs. It will be massively helpful for both design decision and learning.
Allocate in-job
Blittable bool
Burst ECB
etc.
I am indeed. The only thing is… I NEED to be able to do this in job code since I am currently working on a Marching Cubes implementation, however, I could probably avoid the need to make this array by going straight to getting values from the _voxel array. I can do the same for corners. Then, I can actually use the pre existing vertices buffer as a placeholder for my values that would normally be stored into the verlist NativeArray.
Razmot
November 18, 2018, 9:44pm
5
you can allocate a big array in onUpdate
var megaVertexBuffer = new NativeArray<short>(buffer_stride * _group.Length, Allocator.TempJob);
var surfJob = new SurfaceJobP
{
...
megaVertexBuffer = megaVertexBuffer
Define it in your job like that
private struct SurfaceJobP : IJobProcessComponentDataWithEntity<VoxelChunk>
{
[DeallocateOnJobCompletion] [NativeDisableParallelForRestriction] internal NativeArray<short> megaVertexBuffer;
And use it like that :
public void Execute(Entity e, int i, ref VoxelChunk vox)
{
var vertexBuffer = megaVertexBuffer.Slice(i * buffer_stride, buffer_stride);
That works fine in burst, and DeallocateOnJobCompletion is smart enough.