Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ObiNativeList memory leak?
#1
I'm using Obi Cloth 7.0.3, in Unity version 2022.3.51f1.

We have a system that automatically generates meshes and turns them into cloths. We've been troubleshooting issues with inconsistent cloth behaviour, and noticed some leaks. The messages don't seem to specify if they're memory leaks, handle leaks or some other kind of leak.

One of the leak logs. They're all related to line 256 of ObiNativeList, and all occur as a consequence of the solver running Initialize() as part of InsertBufferedActor():
Code:
Found 1 leak(s) from callstack:
0x000002c3843952e3 (Mono JIT Code) UnityEngine.GraphicsBuffer:.ctor (UnityEngine.GraphicsBuffer/Target,int,int)
0x000002c6ab4f44a3 (Mono JIT Code) Obi.ObiNativeList`1<Obi.ForceZone>:AsComputeBuffer<Obi.ForceZone> (int,UnityEngine.GraphicsBuffer/Target) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/DataStructures/NativeList/ObiNativeList.cs:256)
0x000002c6ab4f43cb (Mono JIT Code) Obi.ObiNativeList`1<Obi.ForceZone>:SafeAsComputeBuffer<Obi.ForceZone> (UnityEngine.GraphicsBuffer/Target) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/DataStructures/NativeList/ObiNativeList.cs:239)
0x000002c6ab4f431b (Mono JIT Code) Obi.ComputeColliderWorld:SetForceZones (Obi.ObiNativeForceZoneList) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Backends/Compute/Collisions/ComputeColliderWorld.cs:239)
0x000002c383c08eea (Mono JIT Code) Obi.ObiColliderWorld:UpdateWorld (single) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Collisions/ObiColliderWorld.cs:600)
0x000002c6ab4e105b (Mono JIT Code) Obi.ObiSolver:Initialize () (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1267)
0x000002c6ab4e036b (Mono JIT Code) Obi.ObiSolver:InsertBufferedActor (Obi.ObiActor) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1971)
0x000002c383c1c343 (Mono JIT Code) Obi.ObiSolver:StartSimulation (single,int) (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1611)
0x000002c383c1b8b3 (Mono JIT Code) Obi.ObiSolver:LateUpdate () (at C:/Users/marcu/Documents/Bitbucket/Standalone stencil test/Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1171)
0x000002c384ad7ae8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ff8fe104c2e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ff8fe03d254 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3068)
0x00007ff8fe03d3cc (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3115)
0x00007ff616b87104 (Unity) scripting_method_invoke
0x00007ff616b64d14 (Unity) ScriptingInvocation::Invoke
0x00007ff616b4c4a4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff616b4c5ca (Unity) MonoBehaviour::CallUpdateMethod
0x00007ff6165de82b (Unity) BaseBehaviourManager::CommonUpdate<LateBehaviourManager>
0x00007ff6165e59fa (Unity) LateBehaviourManager::Update

I know we haven't altered any of this code. The leaks don't occur the first time I enter Play Mode, but do occur after exiting and re-entering Play Mode. It might be a bug with Obi Cloth itself, but the more likely explanation is I'm creating some data that's not being properly disposed of after exiting Play Mode. Then on the next play, the cloth simulation looks for data that has since been destroyed, which causes both the leakage and wonky cloth physics.
What data is created as part of Obi Cloth's standard functionality, that needs to be manually disposed of by the user? I updated the Obi Cloth version to 7.0.3 from 6.5.4, so I imagine there's some part of our code that would have worked fine with the previous version.

Thanks!
Reply
#2
Hi there!

I'm unable to reproduce this. These leaks refer to the compute buffers that get created when initializing force zones, these get released when the last force zone in the scene is removed. I just checked and the Dispose() method on these buffers gets called properly. Note none of these need to be manually disposed of by the user.

Would it be possible for you to share a repro project with us (by sending to support(at)virtualmethdstudio.com) so that we can take a closer look at this?

kind regards,
Reply