From b5ffba3291a3298595d1b0165d415a1fce490fad Mon Sep 17 00:00:00 2001 From: "mr.greywater" Date: Mon, 9 Feb 2015 13:14:45 +0100 Subject: [PATCH] D3D: Added GetDebugObjectName and parameter checking in SetDebugObjectName --- Source/Core/VideoBackends/D3D/D3DBase.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/D3D/D3DBase.h b/Source/Core/VideoBackends/D3D/D3DBase.h index 05190bd5d4..a0a629ac8a 100644 --- a/Source/Core/VideoBackends/D3D/D3DBase.h +++ b/Source/Core/VideoBackends/D3D/D3DBase.h @@ -70,10 +70,29 @@ void SetDebugObjectName(T resource, const char* name) static_assert(std::is_convertible::value, "resource must be convertible to ID3D11DeviceChild*"); #if defined(_DEBUG) || defined(DEBUGFAST) - resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(name), name); + if (resource) + resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)(name ? strlen(name) : 0), name); #endif } +template +std::string GetDebugObjectName(T resource) +{ + static_assert(std::is_convertible::value, + "resource must be convertible to ID3D11DeviceChild*"); + std::string name; +#if defined(_DEBUG) || defined(DEBUGFAST) + if (resource) + { + UINT size = 0; + resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, nullptr); //get required size + name.resize(size); + resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, const_cast(name.data())); + } +#endif + return name; +} + } // namespace D3D typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**);