Browse Source

Fix off by 1 errors in asserts relating to cMaxBodyIndex

Fixes #1486
Jorrit Rouwe 6 months ago
parent
commit
b2eb3cb3e1
2 changed files with 2 additions and 2 deletions
  1. 1 1
      Jolt/Physics/Body/BodyID.h
  2. 1 1
      Jolt/Physics/PhysicsSystem.cpp

+ 1 - 1
Jolt/Physics/Body/BodyID.h

@@ -36,7 +36,7 @@ public:
 	explicit				BodyID(uint32 inID, uint8 inSequenceNumber) :
 		mID((uint32(inSequenceNumber) << 24) | inID)
 	{
-		JPH_ASSERT(inID < cMaxBodyIndex); // Should not use bit pattern for invalid ID and should not use the broadphase bit
+		JPH_ASSERT(inID <= cMaxBodyIndex); // Should not overlap with broadphase bit or sequence number
 	}
 
 	/// Get index in body array

+ 1 - 1
Jolt/Physics/PhysicsSystem.cpp

@@ -77,7 +77,7 @@ PhysicsSystem::~PhysicsSystem()
 
 void PhysicsSystem::Init(uint inMaxBodies, uint inNumBodyMutexes, uint inMaxBodyPairs, uint inMaxContactConstraints, const BroadPhaseLayerInterface &inBroadPhaseLayerInterface, const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, const ObjectLayerPairFilter &inObjectLayerPairFilter)
 {
-	JPH_ASSERT(inMaxBodies <= BodyID::cMaxBodyIndex, "Cannot support this many bodies");
+	JPH_ASSERT(inMaxBodies <= BodyID::cMaxBodyIndex + 1, "Cannot support this many bodies");
 
 	mObjectVsBroadPhaseLayerFilter = &inObjectVsBroadPhaseLayerFilter;
 	mObjectLayerPairFilter = &inObjectLayerPairFilter;