Why internal DirectX 11 overlays crash when the user Alt-Tabs or changes display resolution:
When resolution changes, the game calls IDXGISwapChain::ResizeBuffers. If your overlay still holds references to the ID3D11RenderTargetView, ResizeBuffers fails with DXGI_ERROR_INVALID_CALL and crashes!
The Fix:
Hook ResizeBuffers (VTable index 13):
HRESULT __stdcall hkResizeBuffers(IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) {
if (g_pRenderTargetView) {
g_pContext->OMSetRenderTargets(0, nullptr, nullptr);
g_pRenderTargetView->Release();
g_pRenderTargetView = nullptr;
}
HRESULT hr = oResizeBuffers(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags);
CreateRenderTarget(pSwapChain); // Recreate RTV for new backbuffer
return hr;
}