reactphysics3d
reactphysics3d copied to clipboard
Fix bug that breaks transforming a Collider on a CollisionBody
Hi there, I've been implementing CollisionBodys and Colliders in a game engine, but during testing I struggled to apply transformations to colliders. After calling setLocalToBodyTransform(), I would get the following error:
Assertion failed: mMapEntityToComponentIndex.containsKey(bodyEntity), file C:\(...)\reactphysics3d\include\reactphysics3d/components/RigidBodyComponents.h, line 418
That references this assertion:
// Return true if the body is sleeping
RP3D_FORCE_INLINE bool RigidBodyComponents::getIsSleeping(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
return mIsSleeping[mMapEntityToComponentIndex[bodyEntity]];
}
I found it odd that I was hitting an assertion in a RigidBody method despite not utilising RigidBodys. I believe this is due to some undefined behavior, since static_cast isn't guaranteed to return nullptr if the body isn't a RigidBody, so it then proceeds to try to call some methods it probably shouldn't :D
Switching to dynamic_cast has fixed my issue.
Thanks a lot for taking the time to report to fix this. You are right the static_cast seems wrong here.