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.
  2. The 2022.2 beta is now available for testing. To find out what's new, have a look at our 2022.2 feature highlights.
    Dismiss Notice
Dismiss Notice
Submit bug reports tagged with #Beta2022Win_Unity when you encounter unknown issues while testing the 2022.2 betas for a chance to win a year of Unity Pro. For more information, have a look at our Beta Sweepstakes Announcement.

Allocate NativeArray in Execute() and Allocator.Temp

Discussion in '2018.3 Beta' started by ahmidou, Dec 11, 2018.

  1. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    Hi,
    According to the improvement list:
    Scripting: Allocator.Temp memory in NativeContainer types is now automatically disposed of when returning from managed code back to native. Also enforced the restriction of passing Allocator.Temp memory to jobs, which enables the use of Allocator.Temp NativeContainer types in Burst compiled jobs​
    this should work right?

    I'm getting this error in the RC1:
    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 <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00523] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00018] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.Compile (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0001e] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.ProcessBlock (Burst.Compiler.IL.Syntax.ILBlock block) [0x0009a] in <8ccfa83e0f984072892c29638c340c1a>:0
    --- End of inner exception stack trace ---
    at Burst.Compiler.IL.ILVisitor.ProcessBlock (Burst.Compiler.IL.Syntax.ILBlock block) [0x000e9] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.ProcessBlocks () [0x0002e] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.ProcessFunctionBody (Burst.Compiler.IL.Syntax.ILFunction function) [0x00103] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.VisitPendingFunctions () [0x0000e] in <8ccfa83e0f984072892c29638c340c1a>:0
    --- End of inner exception stack trace ---
    at Burst.Compiler.IL.ILVisitor.VisitPendingFunctions () [0x00033] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.VisitEntryPointFunction (Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00066] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVisitor.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x0001a] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILVerifier.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00000] in <8ccfa83e0f984072892c29638c340c1a>:0
    --- End of inner exception stack trace ---
    at Burst.Compiler.IL.ILVerifier.VisitEntryPointFunction (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x0001f] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.ILHash.CompileHash (Burst.Backend.Module module, Burst.Compiler.IL.MethodReferenceWithHash methodReference) [0x00000] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.NativeCompiler.ComputeHash () [0x000ea] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.Jit.JitCompiler.CompileMethod (Mono.Cecil.MethodReference methodReference, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x000aa] in <8ccfa83e0f984072892c29638c340c1a>:0
    at Burst.Compiler.IL.Jit.JitCompilerService.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job) [0x002b2] in <8ccfa83e0f984072892c29638c340c1a>:0

    While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct`1<ComputeOSD/OsdKernel2f>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
     
  2. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    here's the job:

    Code (CSharp):
    1.     [BurstCompile]
    2.     private struct OsdKernel2f : IJobParallelFor
    3.     {
    4.         public int m_SRC_STRIDE;
    5.         public int m_DST_STRIDE;
    6.         public KernelUniformArgs args;
    7.  
    8.         [ReadOnly]
    9.         [NativeDisableContainerSafetyRestriction]
    10.         public NativeArray<int> offsets;
    11.         [ReadOnly]
    12.         [NativeDisableContainerSafetyRestriction]
    13.         public NativeArray<int> sizes;
    14.         [ReadOnly]
    15.         [NativeDisableContainerSafetyRestriction]
    16.         public NativeArray<int> indices;
    17.         [ReadOnly]
    18.         [NativeDisableContainerSafetyRestriction]
    19.         public NativeArray<float> weights;
    20.         [ReadOnly]
    21.         [NativeDisableContainerSafetyRestriction]
    22.         public NativeArray<Vector2> inVertices;
    23.         [NativeDisableParallelForRestriction]
    24.         [NativeDisableContainerSafetyRestriction]
    25.         public NativeArray<float> dstBuffer;
    26.  
    27.         NativeArray<float> readVertex(int index)
    28.         {
    29.             NativeArray<float> v = new NativeArray<float>(2, Allocator.Temp);
    30.             int vertexIndex = args.srcOffset + index /* m_SRC_STRIDE*/;
    31.             for (int i = 0; i < args.length; ++i)
    32.             {
    33.                 v[i] = inVertices[vertexIndex][i];
    34.             }
    35.             return v;
    36.         }
    37.  
    38.  
    39.         void WriteVertexSeparate(int index, NativeArray<float> v, int dstOffset, NativeArray<float> dstVertexBuffer)
    40.         {
    41.             int vertexIndex = dstOffset + index * m_DST_STRIDE;
    42.             for (int i = 0; i < args.length; ++i)
    43.             {
    44.                 dstVertexBuffer[vertexIndex + i] = v[i];
    45.             }
    46.         }
    47.  
    48.         void AddWithWeight(ref NativeArray<float> v, NativeArray<float> src, float weight)
    49.         {
    50.             for (int i = 0; i < args.length; ++i)
    51.             {
    52.                 v[i] += weight * src[i];
    53.             }
    54.         }
    55.  
    56.         public void Execute(int i)
    57.         {
    58.             int current = i + args.batchStart;
    59.  
    60.             if (current >= args.batchEnd)
    61.             {
    62.                 return;
    63.             }
    64.             NativeArray<float> dst = new NativeArray<float>(2, Allocator.Temp);
    65.  
    66.             int offset = offsets[current],
    67.                 size = sizes[current];
    68.  
    69.             for (int j = 0; j < size; j++)
    70.             {
    71.                 AddWithWeight(ref dst, readVertex(indices[offset + j]), weights[offset + j]);
    72.             }
    73.  
    74.             WriteVertexSeparate(current, dst, args.dstOffset, dstBuffer);
    75.         }
    76.     }
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,287
    Could you please submit a bug-report, as described in this document:
    https://unity3d.com/unity/beta/guide-to-beta-testing#tab-3

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. Please post this Case number here (in this forum thread) for Unity staff to pick up.
     
    LeonhardP likes this.
  4. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    Is there a way to submit a bug using a web browser? I'm behind a firewall and can't use the bug reporter...
     
unityunity