Search Unity

Feedback Bugs from implicit cast of NativeList to NativeArray

Discussion in 'Entity Component System' started by BrendonSmuts, Apr 9, 2021.

  1. BrendonSmuts

    BrendonSmuts

    Joined:
    Jun 12, 2017
    Posts:
    86
    I run into no small number of bugs due to the implicit cast from NativeLists to NativeArrays. The scenario is almost always the same:

    I have a job that populates a NativeList, a second job that works with a NativeArray, and some main thread scheduling that passes the list to JobA and then to JobB, missing the intended AsDeferredJobArray() call and silently casting the not yet populated list to a zero length array.

    Because in almost every case the work being done in the second job is checked against the bounds of the array, with zero length arrays being an acceptable case, these bad assignments throw no exceptions and simply produce unexpected results that take time to narrow down and identify.

    Is there really that much benefit to having this conversion implicit? Is it just me that this bites in the ass?
     
    Last edited: Apr 12, 2021
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    I'm with you on this; I'm not a fan of this type of implicit cast as I find it leads to a lot of bugs.
     
    MNNoxMortem likes this.