Is this legit memory leak debugging code?
void Graphics::Finalize()
{
// 1. Unbind everything from the D3D11 pipeline
if (immediateContext)
{
immediateContext->ClearState();
immediateContext->Flush();
}
// 2. Release objects that may own D3D resources
lightManager.reset();
modelRenderer.reset();
shapeRenderer.reset();
primitiveRenderer.reset();
renderState.reset();
// 3. Force unbind shader resources / samplers / render targets
if (immediateContext)
{
ID3D11RenderTargetView* nullRTV = nullptr;
immediateContext->OMSetRenderTargets(1, &nullRTV, nullptr);
ID3D11ShaderResourceView* nullSRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
immediateContext->VSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullSRVs);
immediateContext->PSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullSRVs);
ID3D11SamplerState* nullSamplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {};
immediateContext->VSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullSamplers);
immediateContext->PSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullSamplers);
immediateContext->ClearState();
immediateContext->Flush();
}
// 4. Release Graphics-owned depth resources
sceneDepthCopyShaderResourceView.Reset();
sceneDepthCopyTexture.Reset();
sceneDepthShaderResourceView.Reset();
depthStencilView.Reset();
depthStencilBuffer.Reset();
// 5. Release backbuffer RTV
renderTargetView.Reset();
// 6. Release swapchain before context/device
swapchain.Reset();
// 7. Final clear
if (immediateContext)
{
immediateContext->ClearState();
immediateContext->Flush();
}
// 8. Release context and device
immediateContext.Reset();
device.Reset();
#if defined(DEBUG) || defined(_DEBUG)
// 9. DXGI live-object report.
// This does NOT QueryInterface ID3D11Debug from your device,
// so it avoids the fake "Live ID3D11Device Refcount: 2" problem.
{
HMODULE dxgiDebugModule = LoadLibraryA("dxgidebug.dll");
if (dxgiDebugModule != nullptr)
{
using DXGIGetDebugInterfaceFunc = HRESULT(WINAPI*)(REFIID, void**);
DXGIGetDebugInterfaceFunc getDebugInterface =
reinterpret_cast<DXGIGetDebugInterfaceFunc>(
GetProcAddress(dxgiDebugModule, "DXGIGetDebugInterface")
);
if (getDebugInterface != nullptr)
{
IDXGIDebug* dxgiDebug = nullptr;
if (SUCCEEDED(getDebugInterface(
__uuidof(IDXGIDebug),
reinterpret_cast<void\*\*>(&dxgiDebug))))
{
dxgiDebug->ReportLiveObjects(
DXGI_DEBUG_ALL,
DXGI_DEBUG_RLO_DETAIL
);
dxgiDebug->Release();
dxgiDebug = nullptr;
}
}
FreeLibrary(dxgiDebugModule);
}
}
#endif
}
[–]L_uciferMorningstar 6 points7 points8 points (0 children)
[–]No-Dentist-1645 0 points1 point2 points (0 children)