01-12-2023, 07:36 AM
(This post was last modified: 01-12-2023, 07:36 AM by josemendez.)
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:
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
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