Browse Source

Fix: Body with EMotionType::LinearCast will trigger assert against a soft body (#849)

This will only stop the CCD body against the soft body but will not give a proper impulse during the CCD step (it will in the subsequent discrete time step). Fixing this will come later.

See #845
Jorrit Rouwe 1 year ago
parent
commit
a2b6361777
1 changed files with 5 additions and 0 deletions
  1. 5 0
      Jolt/Physics/PhysicsSystem.cpp

+ 5 - 0
Jolt/Physics/PhysicsSystem.cpp

@@ -1527,6 +1527,7 @@ void PhysicsSystem::JobIntegrateVelocity(const PhysicsUpdateContext *ioContext,
 					{
 					{
 						// This body needs a cast
 						// This body needs a cast
 						uint32 ccd_body_idx = ioStep->mNumCCDBodies++;
 						uint32 ccd_body_idx = ioStep->mNumCCDBodies++;
+						JPH_ASSERT(active_body_idx < ioStep->mNumActiveBodyToCCDBody);
 						ioStep->mActiveBodyToCCDBody[active_body_idx] = ccd_body_idx;
 						ioStep->mActiveBodyToCCDBody[active_body_idx] = ccd_body_idx;
 						new (&ioStep->mCCDBodies[ccd_body_idx]) CCDBody(body_id, delta_pos, linear_cast_threshold_sq, min(mPhysicsSettings.mPenetrationSlop, mPhysicsSettings.mLinearCastMaxPenetration * inner_radius));
 						new (&ioStep->mCCDBodies[ccd_body_idx]) CCDBody(body_id, delta_pos, linear_cast_threshold_sq, min(mPhysicsSettings.mPenetrationSlop, mPhysicsSettings.mLinearCastMaxPenetration * inner_radius));
 
 
@@ -1614,6 +1615,10 @@ inline static Vec3 sCalculateBodyMotion(const Body &inBody, float inDeltaTime)
 // Helper function that finds the CCD body corresponding to a body (if it exists)
 // Helper function that finds the CCD body corresponding to a body (if it exists)
 inline static PhysicsUpdateContext::Step::CCDBody *sGetCCDBody(const Body &inBody, PhysicsUpdateContext::Step *inStep)
 inline static PhysicsUpdateContext::Step::CCDBody *sGetCCDBody(const Body &inBody, PhysicsUpdateContext::Step *inStep)
 {
 {
+	// Only rigid bodies can have a CCD body
+	if (!inBody.IsRigidBody())
+		return nullptr;
+
 	// If the body has no motion properties it cannot have a CCD body
 	// If the body has no motion properties it cannot have a CCD body
 	const MotionProperties *motion_properties = inBody.GetMotionPropertiesUnchecked();
 	const MotionProperties *motion_properties = inBody.GetMotionPropertiesUnchecked();
 	if (motion_properties == nullptr)
 	if (motion_properties == nullptr)