Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from using _DEBUG to NDEBUG #1049

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jolt/ConfigurationString.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline const char *GetConfigurationString()
#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
"(FP Exceptions) "
#endif
#ifdef _DEBUG
#ifdef JPH_DEBUG
"(Debug) "
#endif
;
Expand Down
9 changes: 7 additions & 2 deletions Jolt/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Jolt/Core/IssueReporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Jolt/Core/LockFreeHashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class LockFreeHashMap : public NonCopyable
Iterator begin();
Iterator end();

#ifdef _DEBUG
#ifdef JPH_DEBUG
/// Output stats about this map to the log
void TraceStats() const;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Jolt/Core/LockFreeHashMap.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Jolt/Geometry/EPAConvexHullBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class EPAConvexHullBuilder : public NonCopyable
{
// Destruct triangle
inT->~Triangle();
#ifdef _DEBUG
#ifdef JPH_DEBUG
memset(inT, 0xcd, sizeof(Triangle));
#endif

Expand Down
4 changes: 2 additions & 2 deletions Jolt/Geometry/GJKClosestPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class GJKClosestPoint : public NonCopyable
break;

case 4:
#ifdef _DEBUG
#ifdef JPH_DEBUG
memset(&outPointA, 0xcd, sizeof(outPointA));
memset(&outPointB, 0xcd, sizeof(outPointB));
#endif
Expand Down Expand Up @@ -393,7 +393,7 @@ class GJKClosestPoint : public NonCopyable
#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
Expand Down
16 changes: 8 additions & 8 deletions Jolt/Physics/Body/BodyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -1144,6 +1144,6 @@ void BodyManager::ValidateActiveBodyBounds()
JPH_ASSERT(cached == calculated);
}
}
#endif // _DEBUG
#endif // JPH_DEBUG

JPH_NAMESPACE_END
8 changes: 4 additions & 4 deletions Jolt/Physics/Body/BodyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ class JPH_EXPORT BodyManager : public NonCopyable
};
#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
Expand All @@ -299,10 +299,10 @@ class JPH_EXPORT BodyManager : public NonCopyable
/// 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;
Expand Down
8 changes: 4 additions & 4 deletions Jolt/Physics/Collision/BroadPhase/QuadTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Jolt/Physics/Collision/BroadPhase/QuadTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class JPH_EXPORT QuadTree : public NonCopyable
/// 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;
Expand Down
4 changes: 2 additions & 2 deletions Jolt/Physics/Constraints/ConstraintPart/AxisConstraintPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AxisConstraintPart
}
else
{
#ifdef _DEBUG
#ifdef JPH_DEBUG
Vec3::sNaN().StoreFloat3(&mR1PlusUxAxis);
#endif
}
Expand All @@ -99,7 +99,7 @@ class AxisConstraintPart
}
else
{
#ifdef _DEBUG
#ifdef JPH_DEBUG
Vec3::sNaN().StoreFloat3(&mR2xAxis);
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Jolt/Physics/LargeIslandSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Jolt/Physics/PhysicsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tests/ConvexCollision/RandomRayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Samples/Tests/General/MultithreadedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tests/Rig/RigPileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tests/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions TestFramework/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <d3dcompiler.h>
#include <shellscalingapi.h>
#ifdef _DEBUG
#ifdef JPH_DEBUG
#include <d3d12sdklayers.h>
#endif

Expand Down Expand Up @@ -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))))
Expand Down Expand Up @@ -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)))
Expand All @@ -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));
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading