From a83dc462f7a2b4a090226dbb758fc1cab20ff8e0 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 22 Nov 2018 14:06:19 +0000 Subject: [PATCH] Ensure optional interfaces are correctly initialised to NULL --- renderdoc/driver/d3d12/d3d12_commands.cpp | 63 +++++++++++++++++++++-- renderdoc/driver/d3d12/d3d12_device.cpp | 45 ++++++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 9cb4718ed..6c1b28902 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -204,6 +204,7 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real, RenderDoc::Inst().GetCrashHandler()->RegisterMemoryRegion(this, sizeof(WrappedID3D12CommandQueue)); + m_WrappedDebug.m_pReal = NULL; if(m_pReal) m_pReal->QueryInterface(__uuidof(ID3D12DebugCommandQueue), (void **)&m_WrappedDebug.m_pReal); @@ -261,6 +262,19 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::QueryInterface(REFIID riid, AddRef(); return S_OK; } + else if(riid == __uuidof(ID3D12DebugCommandQueue)) + { + if(m_WrappedDebug.m_pReal) + { + AddRef(); + *ppvObject = (ID3D12DebugCommandQueue *)&m_WrappedDebug; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } else if(riid == __uuidof(ID3D12Pageable)) { *ppvObject = (ID3D12Pageable *)this; @@ -782,15 +796,19 @@ WrappedID3D12GraphicsCommandList2::WrappedID3D12GraphicsCommandList2(ID3D12Graph RenderDoc::Inst().GetCrashHandler()->RegisterMemoryRegion( this, sizeof(WrappedID3D12GraphicsCommandList2)); + m_pList1 = NULL; + m_pList2 = NULL; + + m_WrappedDebug.m_pReal = NULL; + m_WrappedDebug.m_pReal1 = NULL; + m_WrappedDebug.m_pReal2 = NULL; + if(m_pList) { m_pList->QueryInterface(__uuidof(ID3D12DebugCommandList), (void **)&m_WrappedDebug.m_pReal); m_pList->QueryInterface(__uuidof(ID3D12DebugCommandList1), (void **)&m_WrappedDebug.m_pReal1); m_pList->QueryInterface(__uuidof(ID3D12DebugCommandList2), (void **)&m_WrappedDebug.m_pReal2); - m_pList1 = NULL; - m_pList2 = NULL; - m_pList->QueryInterface(__uuidof(ID3D12GraphicsCommandList1), (void **)&m_pList1); m_pList->QueryInterface(__uuidof(ID3D12GraphicsCommandList2), (void **)&m_pList2); } @@ -918,6 +936,45 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12GraphicsCommandList2::QueryInterface(REFI AddRef(); return S_OK; } + else if(riid == __uuidof(ID3D12DebugCommandList)) + { + if(m_WrappedDebug.m_pReal) + { + AddRef(); + *ppvObject = (ID3D12DebugCommandList *)&m_WrappedDebug; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(ID3D12DebugCommandList1)) + { + if(m_WrappedDebug.m_pReal1) + { + AddRef(); + *ppvObject = (ID3D12DebugCommandList1 *)&m_WrappedDebug; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(ID3D12DebugCommandList2)) + { + if(m_WrappedDebug.m_pReal2) + { + AddRef(); + *ppvObject = (ID3D12DebugCommandList2 *)&m_WrappedDebug; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } else if(riid == __uuidof(ID3D12GraphicsCommandList1)) { *ppvObject = (ID3D12GraphicsCommandList1 *)this; diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index b74c9bf10..365928be8 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -256,6 +256,9 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara } m_pInfoQueue = NULL; + m_WrappedDebug.m_pDebug = NULL; + m_WrappedDebug.m_pDebug1 = NULL; + m_WrappedDebug.m_pDebug2 = NULL; if(m_pDevice) { m_pDevice->QueryInterface(__uuidof(ID3D12InfoQueue), (void **)&m_pInfoQueue); @@ -542,6 +545,48 @@ HRESULT WrappedID3D12Device::QueryInterface(REFIID riid, void **ppvObject) return S_OK; } } + else if(riid == __uuidof(ID3D12DebugDevice1)) + { + // we queryinterface for this at startup, so if it's present we can + // return our wrapper + if(m_WrappedDebug.m_pDebug1) + { + AddRef(); + *ppvObject = (ID3D12DebugDevice1 *)&m_WrappedDebug; + return S_OK; + } + else + { + RDCWARN( + "Returning a dummy ID3D12DebugDevice1 that does nothing. This ID3D12DebugDevice1 will " + "not " + "work!"); + *ppvObject = (ID3D12DebugDevice1 *)&m_DummyDebug; + m_DummyDebug.AddRef(); + return S_OK; + } + } + else if(riid == __uuidof(ID3D12DebugDevice2)) + { + // we queryinterface for this at startup, so if it's present we can + // return our wrapper + if(m_WrappedDebug.m_pDebug1) + { + AddRef(); + *ppvObject = (ID3D12DebugDevice2 *)&m_WrappedDebug; + return S_OK; + } + else + { + RDCWARN( + "Returning a dummy ID3D12DebugDevice2 that does nothing. This ID3D12DebugDevice2 will " + "not " + "work!"); + *ppvObject = (ID3D12DebugDevice2 *)&m_DummyDebug; + m_DummyDebug.AddRef(); + return S_OK; + } + } else if(riid == IRenderDoc_uuid) { AddRef();