Search Unity

Null reference unsubscribing from AsyncOperationHandle events

Discussion in 'Addressables' started by jonagill_rr, Aug 16, 2019.

  1. jonagill_rr

    jonagill_rr

    Joined:
    Jun 21, 2017
    Posts:
    33
    I noticed that AsyncOperationHandle has a suite of Action properties (Completed, CompletedTypeless, and Destroyed) that call into some internal functions when added and removed from. Digging in, it appears their backing fields are lazily instantiated the first time you add a callback to them. However, they don't perform nullity checks when performing removal, so if you try to remove before you have ever added a callback, the backing field is null and a cryptic null reference exception is thrown.

    This violates the normal behavior of Action fields (where unsubscribing is always completely safe), and feels like an oversight.
     
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    978
    Definitely an oversight. Thanks for pointing it out.