From a212acd8aa24b1af5410483fa1c48f1b1255651f Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Wed, 4 May 2022 16:25:57 -0700 Subject: [PATCH] Fix crash in ~Log when using GPGMM_ENABLE_ASSERT_ON_WARNING. * Move check outside of Log into Debug.cpp. * Replaces use of Log with EventMessage where ASSERT is not desired. --- src/gpgmm/common/Debug.cpp | 3 +++ src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp | 10 +++++----- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 4 ++-- src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp | 2 +- src/gpgmm/utils/Log.cpp | 4 ---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gpgmm/common/Debug.cpp b/src/gpgmm/common/Debug.cpp index 3de1594f0..339d988f1 100644 --- a/src/gpgmm/common/Debug.cpp +++ b/src/gpgmm/common/Debug.cpp @@ -32,6 +32,9 @@ namespace gpgmm { EventMessage::~EventMessage() { const std::string description = mStream.str(); +#if defined(GPGMM_ENABLE_ASSERT_ON_WARNING) + ASSERT(mSeverity < LogSeverity::Warning); +#endif gpgmm::Log(mSeverity) << mName << ": " << description; if (mSeverity >= gRecordEventLevel) { LOG_MESSAGE message{description, mMessageId}; diff --git a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp index e4a4e3c43..632cb7070 100644 --- a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp @@ -51,11 +51,11 @@ namespace gpgmm { namespace d3d12 { for (auto allocationEntry : mLiveAllocations) { const ResourceAllocation* allocation = allocationEntry->GetValue().GetAllocation(); - gpgmm::WarningLog() << "Live ResourceAllocation: " - << "Addr=" << ToString(allocation) << ", " - << "ExtRef=" << allocation->GetRefCount() << ", " - << "Info=" - << JSONSerializer::Serialize(allocation->GetInfo()).ToString(); + gpgmm::WarnEvent(allocation->GetAllocator()->GetTypename()) + << "Live ResourceAllocation: " + << "Addr=" << ToString(allocation) << ", " + << "ExtRef=" << allocation->GetRefCount() << ", " + << "Info=" << JSONSerializer::Serialize(allocation->GetInfo()).ToString(); } } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 9f5231335..0201b1d98 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1017,8 +1017,8 @@ namespace gpgmm { namespace d3d12 { switch (message->ID) { case D3D12_MESSAGE_ID_LIVE_HEAP: case D3D12_MESSAGE_ID_LIVE_RESOURCE: { - gpgmm::WarningLog() - << "Device leak detected: " + std::string(message->pDescription); + gpgmm::WarnEvent("Device") + << "Leak detected: " + std::string(message->pDescription); } break; default: break; diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index c66e3ef18..57a271b2c 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -86,7 +86,7 @@ namespace gpgmm { namespace d3d12 { ComPtr heap; HRESULT hr = mDevice->CreateHeap(&heapDesc, IID_PPV_ARGS(&heap)); if (FAILED(hr)) { - ErrorLog() << GetTypename() << " failed to create heap: " << GetErrorMessage(hr); + ErrorEvent(GetTypename()) << " failed to create heap: " << GetErrorMessage(hr); return {}; } diff --git a/src/gpgmm/utils/Log.cpp b/src/gpgmm/utils/Log.cpp index cc5fee96e..5fd8e98ee 100644 --- a/src/gpgmm/utils/Log.cpp +++ b/src/gpgmm/utils/Log.cpp @@ -136,10 +136,6 @@ namespace gpgmm { ToString(std::this_thread::get_id()).c_str(), fullMessage.c_str()); fflush(outputStream); #endif - -#if defined(GPGMM_ENABLE_ASSERT_ON_WARNING) - ASSERT(mSeverity < LogSeverity::Warning); -#endif } LogMessage DebugLog() {