Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[BurstDiscard] bug?

Discussion in 'Burst' started by jmedveckyh1, Nov 1, 2018.

  1. jmedveckyh1

    jmedveckyh1

    Joined:
    Jan 15, 2018
    Posts:
    5
    Hello, im using the latest 2018.3 beta and have a question about [BurstDiscard] attribute.

    Im trying to use a job as in this example https://docs.unity3d.com/ScriptReference/Unity.Burst.BurstDiscardAttribute.html

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Jobs;
    4. using UnityEngine;
    5.  
    6. public struct MyJob : IJob
    7. {
    8.     // ...
    9.  
    10.     [BurstDiscard]
    11.     public void NotExecutedInNative()
    12.     {
    13.         Debug.Log("This is a log from a managed job");
    14.     }
    15.  
    16.     public void Execute()
    17.     {
    18.         // The following method call will not be compiled
    19.         NotExecutedInNative();
    20.     }
    21. }
    and it works correctly - the job always outputs the string to the debug console.

    Since i want to use some math heavy code i would like this job to be compiled by burst except the one method executed by the end of the job. So I add a [BurstCompile] attribute to the whole struct such as:

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Jobs;
    4. using UnityEngine;
    5.  
    6. [BurstCompile]
    7. public struct MyJob : IJob
    8. {
    9.     // ...
    10.  
    11.     [BurstDiscard]
    12.     public void NotExecutedInNative()
    13.     {
    14.         Debug.Log("This is a log from a managed job");
    15.     }
    16.  
    17.     public void Execute()
    18.     {
    19.         // math heavy code ...
    20.  
    21.         // The following method call will not be compiled
    22.         NotExecutedInNative();
    23.     }
    24. }
    but this time around the debug string is outputted only a few times and after few seconds it stops. Breakpoints are not hit anymore in the NotExecutedInNative() method and no exception is thrown. The job however is still being executed as i can see from the math heavy code part that it still produces the expected results.

    Is this a bug or am i using the BurstDiscard attribute incorrectly?
    Thanks
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    in the editor, Burst compiles asynchronously and on-demand.
    your job will run in Mono until Burst completes, then switch to Burst

    in a build, you should have only burst jobs if the platform is supported