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. Dismiss Notice

Question Is there any way to have burst safety checks in a build?

Discussion in 'Burst' started by AndrewCzarnietzki, Jun 16, 2023.

  1. AndrewCzarnietzki

    AndrewCzarnietzki

    Joined:
    Jul 23, 2013
    Posts:
    186
    We're trying to track down a particularly obscure issue, and while the editor + safety checks is critical it would be easier if this were in a build. Is there any way to have these safety checks (particularly the native array access out of bounds exception) in a build?

    Thanks!
     
  2. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    I believe the Native Container Safety System is placed in blocks of code surrounded by the
    ENABLE_UNITY_COLLECTIONS_CHECKS
    compilation flag. Adding this flag to a release build should include all of that safety logic, like the out-of-bounds checks you mentioned. For more information on conditional compilation, you can view this page in the documentation. I'm not an expert though, so there's a chance there are more steps required to make it work.
     
  3. AndrewCzarnietzki

    AndrewCzarnietzki

    Joined:
    Jul 23, 2013
    Posts:
    186
    Thank you for the reply!

    Unfortunately Unity fails to build with that flag due to "AtomicSafetyHandle" not being found. From the searching I've done it appears that AtomicSafetyHandle is editor only. Is there any information about including this in some form of build?
     
  4. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Ah... Yeah, sorry about that. Thinking back I may have even encountered that exact problem with Atomic Safety Handles in the past. Unless someone with more knowledge on the field has an answer to this, the only solution I can think of is to code your own drop-in replacement for NativeArrays which does not omit bounds checking at runtime, or have a wrapper class around a NativeArray which does the checks for you. That may not even be too expensive in terms of performance if you inline the wrapper methods and apply similar conditional compilation to your own checks (so they can be removed easily for a final build). Of course that's not a real replacement for Unity's system, however since you're putting most emphasis on bounds checking, this may be the most convenient solution.

    Good luck!
     
  5. AndrewCzarnietzki

    AndrewCzarnietzki

    Joined:
    Jul 23, 2013
    Posts:
    186
    All good and no worries. Would be convenient during development -- having that nice readable stacktrace is useful for the odd thing that slips through vs just having the game 'stop working' spectacularly.

    I appreciate the response!
     
    TriceHelix likes this.
  6. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    50
    Using Burst 1.8.8 (earlier versions might incorrectly strip some non-AtomicSafetyHandle based safety checking functions) DOTS users can define UNITY_DOTS_DEBUG in their project to get bounds checks for Unity.Collection types and simple validation for Entities API calls.

    You however will not get any validation for missing job dependencies / read/write conflicts as those rely on AtomicSafetyHandles which are not currently available in player builds sadly.