-
Hi, I want to implement a collision callback that listens for contact getting removed and when a dynamic body has all contact removed with another static body it flags another system to handle this. So far I've declared a ContactListener, implemented OnContactRemoved and added a very simple BodyInterface::GetMotionType to check if I have a static and dynamic body pair. However I'm hitting an assertion on the LockRead inside GetMotionType. I don't understand why because in the documentation for ContactListener it says I'm only allowed to read from a body, which I'm doing. So why is this not working? Do I need to use the non-locking BodyInterface? To note: I've assigned multiple worker thread to the physics engine so the callback can come from multiple threads. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Reading is recommended when OnContactAdded/Persisted is called. At that point you have a reference to the body and you can use Body::GetMotionType. During OnContactRemoved the bodies may have already been destroyed, so in general it is not safe to access them (this is documented here). As you're apparently tracking how many contacts there are between bodies, you could perhaps use the BodyID's as key and only track pairs you're interested in (ie that have a dynamic body). That way you don't need to read from the bodies when you get a remove callback. |
Beta Was this translation helpful? Give feedback.
Reading is recommended when OnContactAdded/Persisted is called. At that point you have a reference to the body and you can use Body::GetMotionType.
During OnContactRemoved the bodies may have already been destroyed, so in general it is not safe to access them (this is documented here). As you're apparently tracking how many contacts there are between bodies, you could perhaps use the BodyID's as key and only track pairs you're interested in (ie that have a dynamic body). That way you don't need to read from the bodies when you get a remove callback.