Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  "ObjectDisposedException" in cloth objects on scene startup in Unity 2020.3.16f1
#11
Found and fixed the issue. Quick explanation of the cause:

Every simulation step, the solver allocates a temporary native array to hold contact information if collision constraints are enabled. This array is disposed at the end of each timestep.

When the solver is not visible by any camera and deactivated, the contacts array is no longer allocated. However, contact callbacks are still being called, and asking for the size of the (disposed) array. Hence, ObjectDisposedException: Cannot access a disposed object.

Possible solutions are to either stop calling contact callbacks while the solver is out of view, or simply check whether the array exists before asking for its length. I've opted for the second solution, to not break consistency with older versions.

To apply the patch, download and replace the files I'm attaching to this post. They're found in

Assets/Obi/Scripts/Common/Backends/Burst/Constraints/ColliderCollision/

and

Assets/Obi/Scripts/Common/Backends/Burst/Constraints/ParticleCollision/

Let me know how it goes!


Attached Files
.cs   BurstColliderFrictionConstraints.cs (Size: 1.01 KB / Downloads: 14)
.cs   BurstColliderCollisionConstraints.cs (Size: 1.01 KB / Downloads: 12)
.cs   BurstParticleCollisionConstraints.cs (Size: 1.03 KB / Downloads: 11)
.cs   BurstParticleFrictionConstraints.cs (Size: 1.01 KB / Downloads: 16)
Reply
#12
(29-09-2021, 10:58 AM)josemendez Wrote: Found and fixed the issue. Quick explanation of the cause:

Every simulation step, the solver allocates a temporary native array to hold contact information if collision constraints are enabled. This array is disposed at the end of each timestep.

When the solver is not visible by any camera and deactivated, the contacts array is no longer allocated. However, contact callbacks are still being called, and asking for the size of the (disposed) array. Hence, ObjectDisposedException: Cannot access a disposed object.

Possible solutions are to either stop calling contact callbacks while the solver is out of view, or simply check whether the array exists before asking for its length. I've opted for the second solution, to not break consistency with older versions.

To apply the patch, download and replace the files I'm attaching to this post. They're found in

Assets/Obi/Scripts/Common/Backends/Burst/Constraints/ColliderCollision/

and

Assets/Obi/Scripts/Common/Backends/Burst/Constraints/ParticleCollision/

Let me know how it goes!

It worked. Thanks!
Reply
#13
(29-09-2021, 03:21 PM)mattiaswargren Wrote: It worked. Thanks!

Fixed here as well. Thanks, Jose!
Reply