Skip to content

Commit e9278ff

Browse files
committed
fix(d3d11): recreate RTV per-frame instead of ResizeBuffers hook
kiero2 swapchain_methods vtable layout is unreliable for ResizeBuffers (index 13 returns DXGI_ERROR_INVALID_CALL on both test app and game). Instead, recreate RTV from GetBuffer(0) each frame in DX11::Render.
1 parent 525bf37 commit e9278ff

4 files changed

Lines changed: 20 additions & 27 deletions

File tree

‎StArray.ModManager.Windows/Native/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
5757
"${CMAKE_CURRENT_SOURCE_DIR}/../bin/${CMAKE_BUILD_TYPE}/net10.0/"
5858
COMMAND ${CMAKE_COMMAND} -E copy_if_different
5959
"$<TARGET_FILE:${PROJECT_NAME}>"
60-
"D:/Softwares/Steam/steamapps/common/A Dance of Fire and Ice/Corehold/managed"
60+
"D:/Development/RiderProjects/StArray.ModManager/tests/Corehold/managed"
6161
)

‎StArray.ModManager.Windows/Native/hook_d3d11.cpp‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ namespace DX11 {
2121
DEBUG_LOG("D3D11::Init: GetDevice FAILED hr=0x%08X", hr); return;
2222
}
2323
Device->GetImmediateContext(&Context);
24-
25-
ID3D11Texture2D* backBuf = nullptr;
26-
sc->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuf);
27-
if (backBuf) {
28-
Device->CreateRenderTargetView(backBuf, nullptr, &MainRTV);
29-
backBuf->Release();
30-
}
31-
DEBUG_LOG("D3D11::Init: device=%p context=%p rtv=%p", Device, Context, MainRTV);
24+
DEBUG_LOG("D3D11::Init: device=%p context=%p", Device, Context);
3225

3326
imgui_callbacks.init_callback();
3427
ImGui_ImplWin32_Init(g_GameWindow);
@@ -37,7 +30,16 @@ namespace DX11 {
3730
DEBUG_LOG("D3D11::Init: complete");
3831
}
3932

40-
void Render(IDXGISwapChain*) {
33+
void Render(IDXGISwapChain* sc) {
34+
// Recreate RTV each frame from current backbuffer (handles resize automatically)
35+
if (MainRTV) { MainRTV->Release(); MainRTV = nullptr; }
36+
ID3D11Texture2D* backBuf = nullptr;
37+
sc->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuf);
38+
if (backBuf) {
39+
Device->CreateRenderTargetView(backBuf, nullptr, &MainRTV);
40+
backBuf->Release();
41+
}
42+
4143
ImGui_ImplDX11_NewFrame();
4244
if (imgui_callbacks.render_callback) imgui_callbacks.render_callback();
4345
if (MainRTV) Context->OMSetRenderTargets(1, &MainRTV, nullptr);

‎StArray.ModManager.Windows/Native/main.cpp‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,16 @@ HRESULT APIENTRY hkPresent(IDXGISwapChain* sc, UINT sync, UINT flags) {
4141
}
4242
g_OriginalWndProc = (WNDPROC)SetWindowLongPtr(g_GameWindow, GWLP_WNDPROC, (__int3264)(LONG_PTR)WndProc);
4343
ImGui_Initialised = true;
44-
if (g_OriginalWndProc)
45-
DEBUG_LOG("hkPresent: wndproc hooked old=%p new=%p hwnd=%p OK", g_OriginalWndProc, WndProc, g_GameWindow);
46-
else
47-
DEBUG_LOG("hkPresent: SetWindowLongPtr FAILED err=%lu hwnd=%p", GetLastError(), g_GameWindow);
48-
{
49-
RECT cr; GetClientRect(g_GameWindow, &cr);
50-
DXGI_SWAP_CHAIN_DESC sd; sc->GetDesc(&sd);
51-
DEBUG_LOG("hkPresent: clientRect=%dx%d backbuf=%dx%d",
52-
cr.right-cr.left, cr.bottom-cr.top,
53-
sd.BufferDesc.Width, sd.BufferDesc.Height);
54-
}
44+
ImGuiIO* io = igGetIO();
45+
DXGI_SWAP_CHAIN_DESC sd; sc->GetDesc(&sd);
46+
io->DisplaySize.x = (float)sd.BufferDesc.Width; io->DisplaySize.y = (float)sd.BufferDesc.Height;
5547
}
56-
57-
if (GetAsyncKeyState(VK_INSERT) & 1) { ShowMenu = !ShowMenu; DEBUG_LOG("hkPresent: ShowMenu toggled -> %d", ShowMenu); }
58-
59-
ImGuiIO* io = igGetIO();
48+
ImGui_ImplWin32_NewFrame();
49+
// Set DisplaySize AFTER Win32_NewFrame — it overwrites io.DisplaySize with client rect!
50+
/*
6051
{ DXGI_SWAP_CHAIN_DESC sd; sc->GetDesc(&sd);
6152
io->DisplaySize.x = (float)sd.BufferDesc.Width; io->DisplaySize.y = (float)sd.BufferDesc.Height; }
62-
ImGui_ImplWin32_NewFrame();
53+
*/
6354

6455
switch (g_SelectedBackend) {
6556
case 4: case 3: // VK/GL: C# render only

‎StArray.ModManager.Windows/UI/ImGUIGLRenderer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static event Action OnRender
4141
}
4242

4343
private bool _initialized;
44-
private Action _onRender = () => { };
44+
private event Action _onRender = () => { };
4545
private bool _imguiInited;
4646
private IntPtr _hwnd;
4747
private IntPtr _origWndProc;

0 commit comments

Comments
 (0)