Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Memory leak warning with GPU compute solver
#1
(Unity 2022.3.61f1, Obi 7.0.5, Windows 10)



Hey there, I've recently been updating my project from Obi 6 to 7, and also switching to use the GPU compute solver. I noticed in the editor after some testing and re-starting play mode, it would pop up 12 warnings with this:

Code:
GarbageCollector disposing of GraphicsBuffer. Please use GraphicsBuffer.Release() or .Dispose() to manually release the buffer.


This wasn't a major issue, however I also started to get crashes on the built version of my game when exiting, with the stack trace in the Player.log ending with:

Code:
ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFC2836FDFB)
0x00007FFC2836FDFB (UnityPlayer) (function-name not available)
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFC27DB3BAE)
0x00007FFC27DB3BAE (UnityPlayer) (function-name not available)
0x00000293A7D6D9DA (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GraphicsBuffer:DestroyBuffer (UnityEngine.GraphicsBuffer)
0x00000293A7D6D8B3 (Mono JIT Code) UnityEngine.GraphicsBuffer:Dispose (bool)
0x00000293A7D6D823 (Mono JIT Code) UnityEngine.GraphicsBuffer:Dispose ()
0x00000293A6AE4D53 (Mono JIT Code) Obi.ObiNativeList`1<Obi.TriangleMeshHeader>:DisposeOfComputeBuffer ()
0x0000029665B30A63 (Mono JIT Code) Obi.ObiNativeList`1<Obi.TriangleMeshHeader>:Dispose (bool)
0x0000029665B309AB (Mono JIT Code) Obi.ObiNativeList`1<Obi.TriangleMeshHeader>:Finalize ()
0x000002937187A18C (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr)
0x00007FFC2B156F77 (mono-2.0-bdwgc) mono_callspec_cleanup
0x00007FFC2B158118 (mono-2.0-bdwgc) mono_gc_finalize_notify
0x00007FFC2B158680 (mono-2.0-bdwgc) mono_gc_finalize_notify
0x00007FFC2B0EF9AB (mono-2.0-bdwgc) mono_profiler_init_etw
0x00007FFC2B0EFBBE (mono-2.0-bdwgc) mono_profiler_init_etw
0x00007FFD51F47374 (KERNEL32) BaseThreadInitThunk
0x00007FFD521BCC91 (ntdll) RtlUserThreadStart


Doing a build with the Development Build flag did not crash on exit but also threw those GarbageCollector warnings.



After some tracing, all of the warnings were coming from ComputeColliderWorld.cs. I added Dispose()s for each of the buffers that were causing problems to the OnDestroy:


Code:
transformsBuffer?.Dispose();
aabbsBuffer?.Dispose();
materialsBuffer?.Dispose();
shapesBuffer?.Dispose();
forceZonesBuffer?.Dispose();
rigidbodiesBuffer?.Dispose();
distanceFieldHeaders?.Dispose();
bihNodes?.Dispose();
triangleMeshHeaders?.Dispose();
dfNodes?.Dispose();
triangles?.Dispose();
vertices?.Dispose();

This fixed the warnings popping up in editor, and the game no longer crashes on exit in the built version. There may be other buffers that also need to be disposed in this component but these were the ones that were causing issues for my game. Just wanted to let you know about this problem.
Reply
#2
(02-05-2025, 02:25 AM)Softscale Wrote: After some tracing, all of the warnings were coming from ComputeColliderWorld.cs. I added Dispose()s for each of the buffers that were causing problems to the OnDestroy:


Code:
transformsBuffer?.Dispose();
aabbsBuffer?.Dispose();
materialsBuffer?.Dispose();
shapesBuffer?.Dispose();
forceZonesBuffer?.Dispose();
rigidbodiesBuffer?.Dispose();
distanceFieldHeaders?.Dispose();
bihNodes?.Dispose();
triangleMeshHeaders?.Dispose();
dfNodes?.Dispose();
triangles?.Dispose();
vertices?.Dispose();

This fixed the warnings popping up in editor, and the game no longer crashes on exit in the built version. There may be other buffers that also need to be disposed in this component but these were the ones that were causing issues for my game. Just wanted to let you know about this problem.

Hi!

I'm unable to reproduce this issue, neither the editor warnings nor the build crashing on exit.

All these buffers you're disposing of in OnDestroy() are already being disposed of in ObiNativeList.cs. In ComputeColliderWorld.cs, you'll see the buffers are created by calls to AsComputeBuffer() on multiple ObiNativeList instances. This creates the buffer, to which the list holds a reference. Once the lists are disposed in ObiColliderWorld.Destroy(), their respective graphics buffers are disposed of as well.

Judging by the stack trace, the call that should dispose of the graphics buffer is failing with an invalid address access. As mentioned I'm unable to reproduce this, would it be possible for you to send a project that exhibits this issue to support(at)virtualmethodstudio.com so that I can take a closer look?

kind regards,
Reply
#3
Yea, I'm not getting this issue with simple scenes like the Obi samples, so it seems to be something with my game since there is a lot that happens at runtime. I'll try and narrow down where things are going wrong, but otherwise this workaround seems to fix my issues for now.
Reply
#4
Okay! Narrowed down the cause and it does seem to be a misconfiguration in one of my scenes but can be recreated fairly easily.

1. Create a new project, install Obi Fluid.
2. Open the "ComputeFluids" sample scene.
3. Create any 3d primitive object (cube, sphere, etc) and add Rigidbody and ObiRigidbody components to it (but not ObiCollider).
4. Enter play mode, exit play mode, and re-enter play mode again.

This causes a number of those "GarbageCollector disposing of GraphicsBuffer." warnings to appear in the console. If the rigidbody object has a proper ObiCollider component these warnings do not appear, nor do they appear with the Burst solver, only GPU compute.

I was not able to recreate the crash on exit with this, so I don't know if that is related to this issue or something else in my game, but it is a bit odd that adding those Dispose calls would also fix the crash if they weren't related.

I'll be going through my game scenes to track down these rogue collider-less rigidbodies. Not sure what if anything you would need to change on your end but there you go.
Reply