Skip to content

Commit 25350a2

Browse files
janbladeclaude
andcommitted
fix: verify the window's real client rect before trusting size-to-window
The previous commit treated any Width==0 && Height==0 descriptor with a non-null OutputWindow as "size to window" and wrapped it as if it were the game's real swapchain. That's not quite safe: a helper/overlay swapchain (Steam, Discord, NVIDIA overlay, etc.) could use this exact same 0x0 idiom against its own tiny/hidden window, and would now get misclassified as the real swapchain instead of correctly falling through to the existing "Overlay call!" path. Check GetClientRect() on OutputWindow instead of just checking the pointer is non-null: a hidden helper window resolves to a tiny or zero client rect, while a game's actual window won't. Only treat the descriptor as size-to-window when the window itself is at least 100x100. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent f1b9fec commit 25350a2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎OptiScaler/hooks/DxgiFactory_Hooks.cpp‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,22 @@ HRESULT DxgiFactoryHooks::CreateSwapChain(IDXGIFactory* realFactory, IUnknown* p
285285
// exactly this way and was previously being misclassified as "Overlay call!" and passed through
286286
// unwrapped, which is why the menu/toast overlay never appeared. Only a genuinely tiny, non-zero
287287
// descriptor (Steam/Discord-style overlay helper swapchains) should still take that path.
288-
bool sizeToWindow =
289-
pDesc->BufferDesc.Width == 0 && pDesc->BufferDesc.Height == 0 && pDesc->OutputWindow != nullptr;
288+
//
289+
// A non-null OutputWindow alone isn't enough to trust, though: a helper/overlay swapchain could
290+
// use this exact same 0x0 idiom against its OWN tiny/hidden window. Check the window's real
291+
// client rect rather than trusting the pointer -- a hidden helper window resolves to a tiny or
292+
// zero rect; the game's actual window won't.
293+
bool sizeToWindow = false;
294+
if (pDesc->BufferDesc.Width == 0 && pDesc->BufferDesc.Height == 0 && pDesc->OutputWindow != nullptr)
295+
{
296+
RECT clientRect {};
297+
if (GetClientRect(pDesc->OutputWindow, &clientRect))
298+
{
299+
auto windowWidth = clientRect.right - clientRect.left;
300+
auto windowHeight = clientRect.bottom - clientRect.top;
301+
sizeToWindow = windowWidth >= 100 && windowHeight >= 100;
302+
}
303+
}
290304

291305
if (!sizeToWindow && (pDesc->BufferDesc.Height < 100 || pDesc->BufferDesc.Width < 100))
292306
{

0 commit comments

Comments
 (0)