Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  [FIXED] Dispose of atomic safety handle error when game start
#5
I'm unable to reproduce the issue on Unity 2022.3, however I could reproduce it in 2023.1. Seems like the ObiNativeList constructor is not being called by Unity when deserializing it in the editor, but the safety handle is destroyed in Dispose() regardless.

Move the atomic safety handle release inside the if (isCreated){} conditional, like so:

Code:
protected void Dispose(bool disposing)
        {
            if (isCreated)
            {

                // dispose of compuse buffer representation:
                if (m_ComputeBuffer != null)
                {
                    m_ComputeBuffer.Dispose();
                }

                // free unmanaged memory buffer:
                UnsafeUtility.Free(m_AlignedPtr, Allocator.Persistent);
                m_AlignedPtr = null;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
                try
                {
                    // dispose of atomic safety handle:
                    AtomicSafetyHandle.CheckDeallocateAndThrow(m_SafetyHandle);
                    AtomicSafetyHandle.Release(m_SafetyHandle);
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }
#endif
            }

        }

This ensures that the safety handle is only attempted to be destroyed if the array has had its constructor called and m_AlignedPtr is not null.

let me know how it goes,

kind regards
Reply


Messages In This Thread
RE: Dispose of atomic safety handle error when game start - by josemendez - 01-12-2023, 07:36 AM