Browse Source

Switch from using _DEBUG to NDEBUG (#1049)

NDEBUG is defined in the standard while _DEBUG is Visual Studio specific.
Jorrit Rouwe 1 year ago
parent
commit
76eb4534be

+ 1 - 1
Jolt/ConfigurationString.h

@@ -62,7 +62,7 @@ inline const char *GetConfigurationString()
 #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
 		"(FP Exceptions) "
 #endif
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 		"(Debug) "
 #endif
 		;

+ 7 - 2
Jolt/Core/Core.h

@@ -478,8 +478,13 @@ static_assert(sizeof(void *) == (JPH_CPU_ADDRESS_BITS == 64? 8 : 4), "Invalid si
 // Stack allocation
 #define JPH_STACK_ALLOC(n)		alloca(n)
 
-// Shorthand for #ifdef _DEBUG / #endif
-#ifdef _DEBUG
+// Determine if we want extra debugging code to be active
+#if !defined(NDEBUG) && !defined(JPH_NO_DEBUG)
+	#define JPH_DEBUG
+#endif
+
+// Shorthand for #ifdef JPH_DEBUG / #endif
+#ifdef JPH_DEBUG
 	#define JPH_IF_DEBUG(...)	__VA_ARGS__
 	#define JPH_IF_NOT_DEBUG(...)
 #else

+ 1 - 1
Jolt/Core/IssueReporting.h

@@ -11,7 +11,7 @@ using TraceFunction = void (*)(const char *inFMT, ...);
 JPH_EXPORT extern TraceFunction Trace;
 
 // Always turn on asserts in Debug mode
-#if defined(_DEBUG) && !defined(JPH_ENABLE_ASSERTS)
+#if defined(JPH_DEBUG) && !defined(JPH_ENABLE_ASSERTS)
 	#define JPH_ENABLE_ASSERTS
 #endif
 

+ 1 - 1
Jolt/Core/LockFreeHashMap.h

@@ -160,7 +160,7 @@ public:
 	Iterator				begin();
 	Iterator				end();
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	/// Output stats about this map to the log
 	void					TraceStats() const;
 #endif

+ 2 - 2
Jolt/Core/LockFreeHashMap.inl

@@ -189,7 +189,7 @@ inline typename LockFreeHashMap<Key, Value>::KeyValue *LockFreeHashMap<Key, Valu
 	// Construct the key/value pair
 	KeyValue *kv = mAllocator.template FromOffset<KeyValue>(write_offset);
 	JPH_ASSERT(intptr_t(kv) % alignof(KeyValue) == 0);
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	memset(kv, 0xcd, size);
 #endif
 	kv->mKey = inKey;
@@ -311,7 +311,7 @@ typename LockFreeHashMap<Key, Value>::Iterator &LockFreeHashMap<Key, Value>::Ite
 	}
 }
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 
 template <class Key, class Value>
 void LockFreeHashMap<Key, Value>::TraceStats() const

+ 1 - 1
Jolt/Geometry/EPAConvexHullBuilder.h

@@ -152,7 +152,7 @@ public:
 		{
 			// Destruct triangle
 			inT->~Triangle();
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 			memset(inT, 0xcd, sizeof(Triangle));
 #endif
 

+ 2 - 2
Jolt/Geometry/GJKClosestPoint.h

@@ -192,7 +192,7 @@ private:
 			break;
 
 		case 4:
-		#ifdef _DEBUG
+		#ifdef JPH_DEBUG
 			memset(&outPointA, 0xcd, sizeof(outPointA));
 			memset(&outPointB, 0xcd, sizeof(outPointB));
 		#endif
@@ -393,7 +393,7 @@ public:
 #ifdef JPH_GJK_DEBUG
 				Trace("Distance bigger than max");
 #endif
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 				memset(&outPointA, 0xcd, sizeof(outPointA));
 				memset(&outPointB, 0xcd, sizeof(outPointB));
 #endif

+ 8 - 8
Jolt/Physics/Body/BodyManager.cpp

@@ -412,7 +412,7 @@ Body *BodyManager::RemoveBodyInternal(const BodyID &inBodyID)
 	return body;
 }
 
-#if defined(_DEBUG) && defined(JPH_ENABLE_ASSERTS)
+#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
 
 void BodyManager::ValidateFreeList() const
 {
@@ -426,7 +426,7 @@ void BodyManager::ValidateFreeList() const
 	JPH_ASSERT(mNumBodies == mBodies.size() - num_freed);
 }
 
-#endif // defined(_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
+#endif // defined(JPH_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
 
 void BodyManager::RemoveBodies(const BodyID *inBodyIDs, int inNumber, Body **outBodies)
 {
@@ -456,9 +456,9 @@ void BodyManager::RemoveBodies(const BodyID *inBodyIDs, int inNumber, Body **out
 		}
 	}
 
-#if defined(_DEBUG) && defined(JPH_ENABLE_ASSERTS)
+#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
 	ValidateFreeList();
-#endif // defined(_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
+#endif // defined(JPH_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
 }
 
 void BodyManager::DestroyBodies(const BodyID *inBodyIDs, int inNumber)
@@ -482,9 +482,9 @@ void BodyManager::DestroyBodies(const BodyID *inBodyIDs, int inNumber)
 		sDeleteBody(body);
 	}
 
-#if defined(_DEBUG) && defined(JPH_ENABLE_ASSERTS)
+#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
 	ValidateFreeList();
-#endif // defined(_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
+#endif // defined(JPH_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
 }
 
 void BodyManager::AddBodyToActiveBodies(Body &ioBody)
@@ -1130,7 +1130,7 @@ void BodyManager::ValidateContactCacheForAllBodies()
 	mBodiesCacheInvalid.clear();
 }
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 void BodyManager::ValidateActiveBodyBounds()
 {
 	UniqueLock lock(mActiveBodiesMutex JPH_IF_ENABLE_ASSERTS(, this, EPhysicsLockTypes::ActiveBodiesList));
@@ -1144,6 +1144,6 @@ void BodyManager::ValidateActiveBodyBounds()
 			JPH_ASSERT(cached == calculated);
 		}
 }
-#endif // _DEBUG
+#endif // JPH_DEBUG
 
 JPH_NAMESPACE_END

+ 4 - 4
Jolt/Physics/Body/BodyManager.h

@@ -275,10 +275,10 @@ public:
 	};
 #endif
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	/// Validate if the cached bounding boxes are correct for all active bodies
 	void							ValidateActiveBodyBounds();
-#endif // _DEBUG
+#endif // JPH_DEBUG
 
 private:
 	/// Increment and get the sequence number of the body
@@ -299,10 +299,10 @@ private:
 	/// Helper function to delete a body (which could actually be a BodyWithMotionProperties)
 	inline static void				sDeleteBody(Body *inBody);
 
-#if defined(_DEBUG) && defined(JPH_ENABLE_ASSERTS)
+#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
 	/// Function to check that the free list is not corrupted
 	void							ValidateFreeList() const;
-#endif // defined(_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
+#endif // defined(JPH_DEBUG) && _defined(JPH_ENABLE_ASSERTS)
 
 	/// List of pointers to all bodies. Contains invalid pointers for deleted bodies, check with sIsValidBodyPointer. Note that this array is reserved to the max bodies that is passed in the Init function so that adding bodies will not reallocate the array.
 	BodyVector						mBodies;

+ 4 - 4
Jolt/Physics/Collision/BroadPhase/QuadTree.cpp

@@ -253,7 +253,7 @@ void QuadTree::UpdatePrepare(const BodyVector &inBodies, TrackingVector &ioTrack
 #endif
 
 	// Assert sane data
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	ValidateTree(inBodies, ioTracking, root_node.mIndex, mNumBodies);
 #endif
 
@@ -386,7 +386,7 @@ void QuadTree::UpdateFinalize([[maybe_unused]] const BodyVector &inBodies, [[may
 	DumpTree(new_root_node.GetNodeID(), StringFormat("%s_POST", mName).c_str());
 #endif
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	ValidateTree(inBodies, inTracking, new_root_node.mIndex, mNumBodies);
 #endif
 }
@@ -801,7 +801,7 @@ void QuadTree::AddBodiesPrepare(const BodyVector &inBodies, TrackingVector &ioTr
 	// so they will stay together as a batch and will make the tree rebuild cheaper
 	outState.mLeafID = BuildTree(inBodies, ioTracking, (NodeID *)ioBodyIDs, inNumber, 0, outState.mLeafBounds);
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	if (outState.mLeafID.IsNode())
 		ValidateTree(inBodies, ioTracking, outState.mLeafID.GetNodeIndex(), inNumber);
 #endif
@@ -1454,7 +1454,7 @@ void QuadTree::FindCollidingPairs(const BodyVector &inBodies, const BodyID *inAc
 	JPH_ASSERT(&root_node == &GetCurrentRoot());
 }
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 
 void QuadTree::ValidateTree(const BodyVector &inBodies, const TrackingVector &inTracking, uint32 inNodeIndex, uint32 inNumExpectedBodies) const
 {

+ 1 - 1
Jolt/Physics/Collision/BroadPhase/QuadTree.h

@@ -314,7 +314,7 @@ private:
 	/// After the function returns ioNodeIDs and ioNodeCenters will be shuffled
 	static void					sPartition4(NodeID *ioNodeIDs, Vec3 *ioNodeCenters, int inBegin, int inEnd, int *outSplit);
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	/// Validate that the tree is consistent.
 	/// Note: This function only works if the tree is not modified while we're traversing it.
 	void						ValidateTree(const BodyVector &inBodies, const TrackingVector &inTracking, uint32 inNodeIndex, uint32 inNumExpectedBodies) const;

+ 2 - 2
Jolt/Physics/Constraints/ConstraintPart/AxisConstraintPart.h

@@ -86,7 +86,7 @@ class AxisConstraintPart
 		}
 		else
 		{
-		#ifdef _DEBUG
+		#ifdef JPH_DEBUG
 			Vec3::sNaN().StoreFloat3(&mR1PlusUxAxis);
 		#endif
 		}
@@ -99,7 +99,7 @@ class AxisConstraintPart
 		}
 		else
 		{
-		#ifdef _DEBUG
+		#ifdef JPH_DEBUG
 			Vec3::sNaN().StoreFloat3(&mR2xAxis);
 		#endif
 		}

+ 2 - 2
Jolt/Physics/LargeIslandSplitter.cpp

@@ -447,7 +447,7 @@ bool LargeIslandSplitter::SplitIsland(uint32 inIslandIndex, const IslandBuilder
 		JPH_ASSERT(constraint_buffer_cur[s] == mContactAndConstraintIndices + split.mConstraintBufferEnd);
 	}
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	// Validate that the splits are indeed not touching the same body
 	for (uint s = 0; s < splits.mNumSplits; ++s)
 	{
@@ -476,7 +476,7 @@ bool LargeIslandSplitter::SplitIsland(uint32 inIslandIndex, const IslandBuilder
 			}
 		}
 	}
-#endif // _DEBUG
+#endif // JPH_DEBUG
 #endif // JPH_ENABLE_ASSERTS
 
 	// Allow other threads to pick up this split island now

+ 4 - 4
Jolt/Physics/PhysicsSystem.cpp

@@ -387,10 +387,10 @@ EPhysicsUpdateError PhysicsSystem::Update(float inDeltaTime, int inCollisionStep
 				PhysicsUpdateContext::Step *next_step = &context.mSteps[step_idx + 1];
 				step.mStartNextStep = inJobSystem->CreateJob("StartNextStep", cColorStartNextStep, [this, next_step]()
 					{
-					#ifdef _DEBUG
+					#ifdef JPH_DEBUG
 						// Validate that the cached bounds are correct
 						mBodyManager.ValidateActiveBodyBounds();
-					#endif // _DEBUG
+					#endif // JPH_DEBUG
 
 						// Store the number of active bodies at the start of the step
 						next_step->mNumActiveBodiesAtStepStart = mBodyManager.GetNumActiveBodies(EBodyType::RigidBody);
@@ -568,10 +568,10 @@ EPhysicsUpdateError PhysicsSystem::Update(float inDeltaTime, int inCollisionStep
 	// We're done with the barrier for this update
 	inJobSystem->DestroyBarrier(barrier);
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	// Validate that the cached bounds are correct
 	mBodyManager.ValidateActiveBodyBounds();
-#endif // _DEBUG
+#endif // JPH_DEBUG
 
 	// Clear the large island splitter
 	mLargeIslandSplitter.Reset(inTempAllocator);

+ 1 - 1
Samples/Tests/ConvexCollision/RandomRayTest.cpp

@@ -34,7 +34,7 @@ void RandomRayTest::TestRay(const char *inTestName, RVec3Arg inRenderOffset, con
 	default_random_engine random(12345);
 	uniform_real_distribution<float> random_scale(-2.0f, 2.0f);
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	const int count = 1000;
 #else
 	const int count = 10000;

+ 2 - 2
Samples/Tests/General/MultithreadedTest.cpp

@@ -66,7 +66,7 @@ void MultithreadedTest::BoxSpawner()
 {
 	JPH_PROFILE_THREAD_START("BoxSpawner");
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	const int cMaxObjects = 100;
 #else
 	const int cMaxObjects = 1000;
@@ -129,7 +129,7 @@ void MultithreadedTest::RagdollSpawner()
 {
 	JPH_PROFILE_THREAD_START("RagdollSpawner");
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	const int cMaxRagdolls = 10;
 #else
 	const int cMaxRagdolls = 50;

+ 1 - 1
Samples/Tests/Rig/RigPileTest.cpp

@@ -32,7 +32,7 @@ const char *RigPileTest::sScenes[] =
 	"Terrain2",
 };
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	const char *RigPileTest::sSceneName = "PerlinMesh";
 	int RigPileTest::sPileSize = 5;
 	int RigPileTest::sNumPilesPerAxis = 2;

+ 1 - 1
Samples/Tests/Test.cpp

@@ -106,7 +106,7 @@ Body &Test::CreateMeshTerrain()
 {
 	const float scale = GetWorldScale();
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	const int n = 50;
 	const float cell_size = scale * 2.0f;
 #else

+ 6 - 6
TestFramework/Renderer/Renderer.cpp

@@ -13,7 +13,7 @@
 
 #include <d3dcompiler.h>
 #include <shellscalingapi.h>
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	#include <d3d12sdklayers.h>
 #endif
 
@@ -189,7 +189,7 @@ void Renderer::Initialize()
 	// Show window
 	ShowWindow(mhWnd, SW_SHOW);
 
-#if defined(_DEBUG)
+#if defined(JPH_DEBUG)
 	// Enable the D3D12 debug layer
 	ComPtr<ID3D12Debug> debug_controller;
 	if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller))))
@@ -245,7 +245,7 @@ void Renderer::Initialize()
 	// Check if we managed to obtain a device
 	FatalErrorIfFailed(result);
 
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	// Enable breaking on errors
 	ComPtr<ID3D12InfoQueue> info_queue;
 	if (SUCCEEDED(mDevice.As(&info_queue)))
@@ -265,7 +265,7 @@ void Renderer::Initialize()
 		filter.DenyList.pIDList = hide;
 		info_queue->AddStorageFilterEntries( &filter );
 	}
-#endif // _DEBUG
+#endif // JPH_DEBUG
 
 	// Disable full screen transitions
 	FatalErrorIfFailed(mDXGIFactory->MakeWindowAssociation(mhWnd, DXGI_MWA_NO_ALT_ENTER));
@@ -656,7 +656,7 @@ void Renderer::SetRenderTarget(Texture *inRenderTarget)
 ComPtr<ID3DBlob> Renderer::CreateVertexShader(const char *inFileName)
 {
 	UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
 #endif
 
@@ -695,7 +695,7 @@ ComPtr<ID3DBlob> Renderer::CreateVertexShader(const char *inFileName)
 ComPtr<ID3DBlob> Renderer::CreatePixelShader(const char *inFileName)
 {
 	UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
-#ifdef _DEBUG
+#ifdef JPH_DEBUG
 	flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
 #endif