Browse Source

Added check that temp allocator is empty at end of step

Jorrit Rouwe 3 years ago
parent
commit
a82817be95
3 changed files with 15 additions and 0 deletions
  1. 6 0
      Jolt/Core/TempAllocator.h
  2. 3 0
      Samples/SamplesApp.cpp
  3. 6 0
      UnitTests/PhysicsTestContext.cpp

+ 6 - 0
Jolt/Core/TempAllocator.h

@@ -75,6 +75,12 @@ public:
 		}
 		}
 	}
 	}
 
 
+	// Check if no allocations have been made
+	bool							IsEmpty() const
+	{
+		return mTop == 0;
+	}
+
 private:
 private:
 	uint8 *							mBase;							///< Base address of the memory block
 	uint8 *							mBase;							///< Base address of the memory block
 	uint							mSize;							///< Size of the memory block
 	uint							mSize;							///< Size of the memory block

+ 3 - 0
Samples/SamplesApp.cpp

@@ -2046,6 +2046,9 @@ void SamplesApp::StepPhysics(JobSystem *inJobSystem)
 
 
 	// Step the world (with fixed frequency)
 	// Step the world (with fixed frequency)
 	mPhysicsSystem->Update(delta_time, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, inJobSystem);
 	mPhysicsSystem->Update(delta_time, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, inJobSystem);
+#ifndef JPH_DISABLE_TEMP_ALLOCATOR
+	JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
+#endif // JPH_DISABLE_TEMP_ALLOCATOR
 
 
 	// Accumulate time
 	// Accumulate time
 	mTotalTime += GetProcessorTickCount() - start_tick;
 	mTotalTime += GetProcessorTickCount() - start_tick;

+ 6 - 0
UnitTests/PhysicsTestContext.cpp

@@ -84,12 +84,18 @@ void PhysicsTestContext::Simulate(float inTotalTime, function<void()> inPreStepC
 	{
 	{
 		inPreStepCallback();
 		inPreStepCallback();
 		mSystem->Update(mDeltaTime, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, mJobSystem);
 		mSystem->Update(mDeltaTime, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, mJobSystem);
+	#ifndef JPH_DISABLE_TEMP_ALLOCATOR
+		JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
+	#endif // JPH_DISABLE_TEMP_ALLOCATOR
 	}
 	}
 }
 }
 
 
 void PhysicsTestContext::SimulateSingleStep()
 void PhysicsTestContext::SimulateSingleStep()
 {
 {
 	mSystem->Update(mDeltaTime, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, mJobSystem);
 	mSystem->Update(mDeltaTime, mCollisionSteps, mIntegrationSubSteps, mTempAllocator, mJobSystem);
+#ifndef JPH_DISABLE_TEMP_ALLOCATOR
+	JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
+#endif // JPH_DISABLE_TEMP_ALLOCATOR
 }
 }
 
 
 Vec3 PhysicsTestContext::PredictPosition(Vec3Arg inPosition, Vec3Arg inVelocity, Vec3Arg inAcceleration, float inTotalTime) const
 Vec3 PhysicsTestContext::PredictPosition(Vec3Arg inPosition, Vec3Arg inVelocity, Vec3Arg inAcceleration, float inTotalTime) const