From efbbc5e62d49885b6be50b1ede92f8596f1a4f28 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Mon, 12 Feb 2024 15:37:27 -0800 Subject: [PATCH] Add NULL checks to CloseHandle in BudgetUpdateTaskDXGI --- src/gpgmm/d3d12/BudgetUpdateDXGI.cpp | 15 ++++++++------- src/gpgmm/d3d12/BudgetUpdateDXGI.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gpgmm/d3d12/BudgetUpdateDXGI.cpp b/src/gpgmm/d3d12/BudgetUpdateDXGI.cpp index 4fe40a8d..e88cbf2c 100644 --- a/src/gpgmm/d3d12/BudgetUpdateDXGI.cpp +++ b/src/gpgmm/d3d12/BudgetUpdateDXGI.cpp @@ -21,7 +21,7 @@ namespace gpgmm::d3d12 { - BudgetUpdateTaskDXGI::BudgetUpdateTaskDXGI(ResidencyManagerDXGI* const residencyManager) + BudgetUpdateTaskDXGI::BudgetUpdateTaskDXGI(ResidencyManagerDXGI* residencyManager) : mResidencyManager(residencyManager), mBudgetNotificationUpdateEvent(CreateEventW(NULL, FALSE, FALSE, NULL)), mUnregisterAndExitEvent(CreateEventW(NULL, FALSE, FALSE, NULL)) { @@ -32,8 +32,12 @@ namespace gpgmm::d3d12 { } BudgetUpdateTaskDXGI::~BudgetUpdateTaskDXGI() { - CloseHandle(mUnregisterAndExitEvent); - CloseHandle(mBudgetNotificationUpdateEvent); + if (mUnregisterAndExitEvent != nullptr) { + ::CloseHandle(mUnregisterAndExitEvent); + } + if (mBudgetNotificationUpdateEvent != nullptr) { + ::CloseHandle(mBudgetNotificationUpdateEvent); + } } MaybeError BudgetUpdateTaskDXGI::operator()() { @@ -52,9 +56,6 @@ namespace gpgmm::d3d12 { if (FAILED(hr)) { break; } - - DebugLog(MessageId::kBudgetUpdated, mResidencyManager) - << "Updated budget from OS notification."; break; } // mUnregisterAndExitEvent @@ -70,7 +71,7 @@ namespace gpgmm::d3d12 { } if (FAILED(hr)) { - ErrorLog(ErrorCode::kBudgetInvalid, mResidencyManager) + ErrorLog(ErrorCode::kBudgetInvalid, mResidencyManager.Get()) << "Unable to update budget: " + GetErrorResultMessage(hr, mResidencyManager->GetDevice()); } diff --git a/src/gpgmm/d3d12/BudgetUpdateDXGI.h b/src/gpgmm/d3d12/BudgetUpdateDXGI.h index 4a4eb84c..78700b11 100644 --- a/src/gpgmm/d3d12/BudgetUpdateDXGI.h +++ b/src/gpgmm/d3d12/BudgetUpdateDXGI.h @@ -27,13 +27,13 @@ namespace gpgmm::d3d12 { BudgetUpdateTaskDXGI(ResidencyManagerDXGI* const residencyManager); ~BudgetUpdateTaskDXGI() override; + private: // VoidCallback interface MaybeError operator()() override; // BudgetUpdateTask interface bool UnregisterAndExit() override; - private: ResidencyManagerDXGI* const mResidencyManager; HANDLE mBudgetNotificationUpdateEvent = INVALID_HANDLE_VALUE;