From 41d5bcfc1b0452434db3f74988a80e0d693d3117 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Wed, 2 Oct 2013 21:43:09 -0700 Subject: [PATCH] DX11: Fixed assert when running with GPA. --- src/renderer_d3d.h | 22 +++++++++------------- src/renderer_d3d11.cpp | 5 ++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index 6d5d638b..c197a338 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -65,26 +65,22 @@ namespace bgfx BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \ } while (0) -# define DX_RELEASE(_ptr, _expected) \ +#else +# define DX_CHECK_REFCOUNT(_ptr, _expected) +#endif // BGFX_CONFIG_DEBUG + +#define _DX_RELEASE(_ptr, _expected, _check) \ do { \ if (NULL != _ptr) \ { \ ULONG count = _ptr->Release(); \ - BX_CHECK(_expected == count, "RefCount is %d (expected %d).", count, _expected); \ + _check(_expected == count, "RefCount is %d (expected %d).", count, _expected); \ _ptr = NULL; \ } \ } while (0) -#else -# define DX_CHECK_REFCOUNT(_ptr, _expected) -# define DX_RELEASE(_ptr, _expected) \ - do { \ - if (NULL != _ptr) \ - { \ - _ptr->Release(); \ - _ptr = NULL; \ - } \ - } while (0) -#endif // BGFX_CONFIG_DEBUG + +#define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK) +#define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN) inline int getRefCount(IUnknown* _interface) { diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 02b1c803..8067f473 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -454,7 +454,10 @@ namespace bgfx hr = device->GetParent(__uuidof(IDXGIAdapter), (void**)&adapter); BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - DX_RELEASE(device, 2); + + // GPA increases device ref count and triggers assert in debug + // build. Warn only instead. + DX_RELEASE_WARNONLY(device, 2); hr = adapter->GetDesc(&m_adapterDesc); BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device.");