crashes when a Ragdoll points to a destroyed PhysicsSystem #1431
Replies: 8 comments 3 replies
-
Unfortunately this is not something that can be fixed. The PhysicsSystem does not know about the existance of the Ragdoll so it cannot destroy it first. Ragdoll is a higher level concept that the physics system should not know about. In general Jolt tries to avoid links between objects as much as possible. This is one of the main reasons why you can do many things in a thread safe way. |
Beta Was this translation helpful? Give feedback.
-
I understand. |
Beta Was this translation helpful? Give feedback.
-
That's not a proper solution either. You can do:
This is quite common as a character may only need an active ragdoll during certain situations (e.g. hit responses), but you want to keep the ragdoll around because it's expensive to create. I don't think this is going to be the only case where destruction order matters and I would suggest looking into a more generic system to handle this. I took a quick look at jolt-jni:
My Java skills are pretty low so excuse me if my suggestions don't make sense. |
Beta Was this translation helpful? Give feedback.
-
That makes sense.
I already track dependencies for C++ objects contained in other C++ objects, such as vectors. However, tracking doesn't help with this issue because it only prevents containers from being cleaned while their contents are strongly reachable. In this issue, neither the ragdoll nor the physics space is strongly reachable.
I don't know of any way to do this. I'll ask around. |
Beta Was this translation helpful? Give feedback.
-
Question: are there other situations in Jolt Physics where the destructor of a high-level object refers to a low-level object with its own destructor? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the brainstorm. |
Beta Was this translation helpful? Give feedback.
-
The
Yes, I need to control the destruction order for
The (to be continued) |
Beta Was this translation helpful? Give feedback.
-
The
Yes, I need to control the destruction order for |
Beta Was this translation helpful? Give feedback.
-
As I mentioned before, I'm creating Java bindings for JoltPhysics. Earlier this month I began experiencing various crashes:
After much experimentation, I've narrowed down the issue. I believe it relates to the order in which destructors for
RagDoll
andPhysicsSystem
are invoked.As you're probably aware, Java programmers aren't accustomed to thinking about object destruction. When using my Java bindings, C++ objects like physics systems and ragdoll references are allocated on the heap, and their destructors typically get invoked by an asynchronous automatic cleanup thread. In this scenario, the Java application cannot control the order in which those destructors are invoked. It's entirely possible for
PhysicsSystem::~PhysicsSystem
to be invoked beforeRagdoll::~Ragdoll
. In that case,~Ragdoll
accesses a destroyedPhysicsSystem
.This scenario is unlikely in C++ applications, where typical coding practices ensure destruction of all ragdolls prior to destruction of the physics system(s) they point to.
I ran an experiment where I disabled my cleanup thread so I could specify the destruction sequence. When the sequence was:
the application always completed successfully, but when the sequence was:
the application crashed every time at Jolt/Core/Array.h:455:
(inIdx < mSize)
.It ought to be possible to modify the
PhysicsSystem
class to keep track of all ragdolls that point to the system so that~PhysicsSystem
can invalidate those pointers. Or perhaps you can devise a better solution.Beta Was this translation helpful? Give feedback.
All reactions