Obi Official Forum
Help [FIXED] Dispose of atomic safety handle error when game start - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Help [FIXED] Dispose of atomic safety handle error when game start (/thread-4065.html)

Pages: 1 2


RE: [FIXED] Dispose of atomic safety handle error when game start - kaser - 04-12-2023

(01-12-2023, 03:22 AM)kaser Wrote:
Code:
System.ObjectDisposedException: The UNKNOWN_OBJECT_TYPE has been deallocated, it is not allowed to access it
  at (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow_Injected(Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle&)
  at Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) [0x00000] in <b41119cc6741409ea29f63c7f98de938>:0
  at Obi.ObiNativeList`1[T].Dispose (System.Boolean disposing) [0x0003f] in ....\Standard Assets\Vendor\Obi\Scripts\Common\DataStructures\NativeList\ObiNativeList.cs


Hi, I got an error message after game start while using the Obi , as shown above.

Please help me to fix this error

The following is the current version information used in the project
Unity 2022.3.6f1
Burst 1.8.8
Jobs 0.70.0-preview(Exp)
URP 14.0.8
Mathematics 1.2.6
Collections 2.1.4

Obi Cloth 6.5.4
Obi Rope 6.5.4

If you need further information, please let me know

12月1日 1:02





I checked the error code and found strange parts. 
The Dispose process used Bool, but it was not actually used in the Function
Therefore, I added a correction, but I am not sure if this correction is correct. 

After more digging . I think Obi's implementation of Create and Dispose may have missed implementations, resulting in Dispose not running properly.
If anyone is also investigating, welcome to join

#5 Solution

ObiNativeList.cs


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
    }

}



RE: [FIXED] Dispose of atomic safety handle error when game start - imtzo - 06-05-2024

I recently ran into this exception when upgrading my project to Unity 2022.3. In case it matters (for reproducing the exception), in my project the ObiRope objects are within a second scene which is loaded after launch.

Before I found this thread I addressed it by adding the following condition checks within the #if ENABLE_UNITY_COLLECTIONS_CHECKS. Both were necessary.

Code:
if (!AtomicSafetyHandle.IsDefaultValue(m_SafetyHandle) && AtomicSafetyHandle.IsHandleValid(m_SafetyHandle))
{
    // dispose of atomic safety handle:
    AtomicSafetyHandle.CheckDeallocateAndThrow(m_SafetyHandle);
    AtomicSafetyHandle.Release(m_SafetyHandle);
}