Fix DX12 menu crash on swapchains with more than 8 buffers

Size the menu's per-buffer arrays and the blur's descriptor slots for 16 back buffers, the DXGI maximum, refuse larger chains in CreateRenderTargetDx12 and skip frames with an out-of-range back buffer index.
This commit is contained in:
Michael Robles authored and Michał Lewandowski committed 2026-10-21 13:28:36 +02:00
1 parent a8d0f0a3cb
commit d06f31e953
2 files changed
+17 -4

No files matched your search

+16 -3
View File
@@ -15,7 +15,8 @@
#include <shaders/menu_blur/MenuBlur_Dx12.h>
// menu
static int const NUM_BACK_BUFFERS = 8;
// Sized for the largest swapchain DXGI allows, the menu can draw on chains created by other layers
static int const NUM_BACK_BUFFERS = 16; // DXGI_MAX_SWAP_CHAIN_BUFFERS
static int const SRV_HEAP_SIZE = 64;
static bool _dx11Device = false;
static bool _dx12Device = false;
@@ -101,6 +102,12 @@ static void CreateRenderTargetDx12(ID3D12Device* device, IDXGISwapChain* pSwapCh
return;
}
if (sd.BufferCount > NUM_BACK_BUFFERS)
{
LOG_ERROR("Swapchain has {} buffers, menu supports {}", sd.BufferCount, NUM_BACK_BUFFERS);
return;
}
for (UINT i = 0; i < sd.BufferCount; ++i)
{
ID3D12Resource* pBackBuffer = nullptr;
@@ -500,10 +507,16 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain)
{
_showRenderImGuiDebugOnce = true;
ImGui_ImplDX12_NewFrame();
UINT backBufferIdx = pSwapChain->GetCurrentBackBufferIndex();
if (backBufferIdx >= NUM_BACK_BUFFERS || !g_mainRenderTargetResource[backBufferIdx])
{
pSwapChain->Release();
return;
}
ImGui_ImplDX12_NewFrame();
// Blur textures are only created once the menu is opened, menu decides if they are used
bool blurReady = false;
if (g_menuBlur || MenuOverlayBase::IsVisible())
+1 -1
View File
@@ -10,7 +10,7 @@
class MenuBlur_Dx12 : public Shader_Dx12, public MenuBlur_Common
{
private:
static constexpr UINT MaxBackBuffers = 8;
static constexpr UINT MaxBackBuffers = 16; // DXGI_MAX_SWAP_CHAIN_BUFFERS
// Descriptor layout, every pass uses a SRV + UAV pair
// [2 * i]: back buffer i SRV, [2 * i + 1]: blur A UAV