Skip to content

Commit

Permalink
Fixed potential mishandling of WM_DESTROY when virtual aspect ratios …
Browse files Browse the repository at this point in the history
…are used
  • Loading branch information
Kaldaien committed Sep 1, 2023
1 parent db1c337 commit 211dd1d
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 29 deletions.
169 changes: 167 additions & 2 deletions SpecialK.ruleset
Original file line number Diff line number Diff line change
@@ -1,41 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for SpecialK" Description="Code analysis rules for SpecialK.vcxproj." ToolsVersion="16.0">
<RuleSet Name="Rules for SpecialK" Description="Code analysis rules for SpecialK.vcxproj." ToolsVersion="17.0">
<Include Path="..\..\..\..\..\..\source\repos\SpecialK\specialk.ruleset" Action="Default" />
<Include Path="basiccorrectnessrules.ruleset" Action="Default" />
<Include Path="basicdesignguidelinerules.ruleset" Action="Default" />
<Include Path="concurrencycheckrules.ruleset" Action="Default" />
<Include Path="concurrencyrules.ruleset" Action="Default" />
<Include Path="cppcorecheckarithmeticrules.ruleset" Action="Default" />
<Include Path="cppcorecheckconcurrencyrules.ruleset" Action="Default" />
<Include Path="cppcorecheckdeclrules.ruleset" Action="Default" />
<Include Path="cppcorecheckexperimentalrules.ruleset" Action="Default" />
<Include Path="cppcorecheckrules.ruleset" Action="Default" />
<Include Path="cppcorecheckstylerules.ruleset" Action="Default" />
<Include Path="extendedcorrectnessrules.ruleset" Action="Default" />
<Include Path="extendeddesignguidelinerules.ruleset" Action="Default" />
<Include Path="globalizationrules.ruleset" Action="Default" />
<Include Path="nativeminimumrules.ruleset" Action="Default" />
<Include Path="nativerecommendedrules.ruleset" Action="Default" />
<Include Path="securityrules.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1501" Action="Warning" />
<Rule Id="CA1502" Action="Warning" />
<Rule Id="CA1505" Action="Warning" />
<Rule Id="CA1506" Action="Warning" />
<Rule Id="CA1600" Action="Warning" />
<Rule Id="CA1725" Action="Warning" />
<Rule Id="CA1800" Action="Warning" />
<Rule Id="CA1801" Action="Warning" />
<Rule Id="CA1804" Action="Warning" />
<Rule Id="CA1809" Action="Warning" />
<Rule Id="CA2001" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
<Rule Id="C26100" Action="Warning" />
<Rule Id="C26101" Action="Warning" />
<Rule Id="C26102" Action="Warning" />
<Rule Id="C26105" Action="Warning" />
<Rule Id="C26106" Action="Warning" />
<Rule Id="C26110" Action="Warning" />
<Rule Id="C26111" Action="Warning" />
<Rule Id="C26112" Action="Warning" />
<Rule Id="C26115" Action="Warning" />
<Rule Id="C26116" Action="Warning" />
<Rule Id="C26117" Action="Warning" />
<Rule Id="C26402" Action="Warning" />
<Rule Id="C26403" Action="Warning" />
<Rule Id="C26407" Action="Warning" />
<Rule Id="C26415" Action="Warning" />
<Rule Id="C26426" Action="Warning" />
<Rule Id="C26427" Action="Warning" />
<Rule Id="C26430" Action="Warning" />
<Rule Id="C26441" Action="Warning" />
<Rule Id="C26444" Action="Warning" />
<Rule Id="C26447" Action="Warning" />
<Rule Id="C26450" Action="Warning" />
<Rule Id="C26451" Action="Warning" />
<Rule Id="C26452" Action="Warning" />
<Rule Id="C26453" Action="Warning" />
<Rule Id="C26454" Action="Warning" />
<Rule Id="C26472" Action="Warning" />
<Rule Id="C26473" Action="Warning" />
<Rule Id="C26477" Action="Warning" />
<Rule Id="C26479" Action="Warning" />
<Rule Id="C26483" Action="Warning" />
<Rule Id="C26489" Action="Warning" />
<Rule Id="C26494" Action="Warning" />
<Rule Id="C26498" Action="Warning" />
<Rule Id="C26810" Action="Warning" />
<Rule Id="C26811" Action="Warning" />
<Rule Id="C26813" Action="Warning" />
<Rule Id="C26814" Action="Warning" />
<Rule Id="C26815" Action="Warning" />
<Rule Id="C26816" Action="Warning" />
<Rule Id="C26817" Action="Warning" />
<Rule Id="C26819" Action="Warning" />
<Rule Id="C26820" Action="Warning" />
<Rule Id="C26822" Action="Warning" />
<Rule Id="C26823" Action="Warning" />
<Rule Id="C26824" Action="Warning" />
<Rule Id="C26825" Action="Warning" />
<Rule Id="C26848" Action="Warning" />
<Rule Id="C26849" Action="Warning" />
<Rule Id="C28020" Action="Warning" />
<Rule Id="C28103" Action="Warning" />
<Rule Id="C28105" Action="Warning" />
<Rule Id="C28106" Action="Warning" />
<Rule Id="C28109" Action="Warning" />
<Rule Id="C28132" Action="Warning" />
<Rule Id="C28182" Action="Warning" />
<Rule Id="C28197" Action="Warning" />
<Rule Id="C28198" Action="Warning" />
<Rule Id="C28199" Action="Warning" />
<Rule Id="C28206" Action="Warning" />
<Rule Id="C28207" Action="Warning" />
<Rule Id="C28287" Action="Warning" />
<Rule Id="C28288" Action="Warning" />
<Rule Id="C28601" Action="Warning" />
<Rule Id="C28602" Action="Warning" />
<Rule Id="C28604" Action="Warning" />
<Rule Id="C28615" Action="Warning" />
<Rule Id="C28617" Action="Warning" />
<Rule Id="C28623" Action="Warning" />
<Rule Id="C28636" Action="Warning" />
<Rule Id="C28637" Action="Warning" />
<Rule Id="C28638" Action="Warning" />
<Rule Id="C28639" Action="Warning" />
<Rule Id="C28648" Action="Warning" />
<Rule Id="C28649" Action="Warning" />
<Rule Id="C28650" Action="Warning" />
<Rule Id="C28719" Action="Warning" />
<Rule Id="C28720" Action="Warning" />
<Rule Id="C28721" Action="Warning" />
<Rule Id="C28726" Action="Warning" />
<Rule Id="C28727" Action="Warning" />
<Rule Id="C28730" Action="Warning" />
<Rule Id="C28735" Action="Warning" />
<Rule Id="C28736" Action="Warning" />
<Rule Id="C28750" Action="Warning" />
<Rule Id="C28751" Action="Warning" />
<Rule Id="C33020" Action="Warning" />
<Rule Id="C33022" Action="Warning" />
<Rule Id="C6001" Action="Warning" />
<Rule Id="C6011" Action="Warning" />
<Rule Id="C6014" Action="Warning" />
<Rule Id="C6053" Action="Warning" />
<Rule Id="C6054" Action="Warning" />
<Rule Id="C6059" Action="Warning" />
<Rule Id="C6063" Action="Warning" />
<Rule Id="C6064" Action="Warning" />
<Rule Id="C6066" Action="Warning" />
<Rule Id="C6067" Action="Warning" />
<Rule Id="C6101" Action="Warning" />
<Rule Id="C6200" Action="Warning" />
<Rule Id="C6201" Action="Warning" />
<Rule Id="C6211" Action="Warning" />
<Rule Id="C6214" Action="Warning" />
<Rule Id="C6215" Action="Warning" />
<Rule Id="C6216" Action="Warning" />
<Rule Id="C6217" Action="Warning" />
<Rule Id="C6219" Action="Warning" />
<Rule Id="C6220" Action="Warning" />
<Rule Id="C6221" Action="Warning" />
<Rule Id="C6225" Action="Warning" />
<Rule Id="C6226" Action="Warning" />
<Rule Id="C6230" Action="Warning" />
<Rule Id="C6237" Action="Warning" />
<Rule Id="C6239" Action="Warning" />
<Rule Id="C6240" Action="Warning" />
<Rule Id="C6242" Action="Warning" />
<Rule Id="C6244" Action="Warning" />
<Rule Id="C6246" Action="Warning" />
<Rule Id="C6255" Action="Warning" />
<Rule Id="C6259" Action="Warning" />
<Rule Id="C6262" Action="Warning" />
<Rule Id="C6263" Action="Warning" />
<Rule Id="C6268" Action="Warning" />
<Rule Id="C6269" Action="Warning" />
<Rule Id="C6270" Action="Warning" />
<Rule Id="C6271" Action="Warning" />
<Rule Id="C6272" Action="Warning" />
<Rule Id="C6273" Action="Warning" />
<Rule Id="C6274" Action="Warning" />
<Rule Id="C6276" Action="Warning" />
<Rule Id="C6277" Action="Warning" />
<Rule Id="C6278" Action="Warning" />
<Rule Id="C6279" Action="Warning" />
<Rule Id="C6280" Action="Warning" />
<Rule Id="C6282" Action="Warning" />
<Rule Id="C6284" Action="Warning" />
<Rule Id="C6287" Action="Warning" />
<Rule Id="C6292" Action="Warning" />
<Rule Id="C6293" Action="Warning" />
<Rule Id="C6295" Action="Warning" />
<Rule Id="C6298" Action="Warning" />
<Rule Id="C6302" Action="Warning" />
<Rule Id="C6303" Action="Warning" />
<Rule Id="C6305" Action="Warning" />
<Rule Id="C6308" Action="Warning" />
<Rule Id="C6310" Action="Warning" />
<Rule Id="C6312" Action="Warning" />
<Rule Id="C6319" Action="Warning" />
<Rule Id="C6320" Action="Warning" />
<Rule Id="C6323" Action="Warning" />
<Rule Id="C6324" Action="Warning" />
<Rule Id="C6326" Action="Warning" />
<Rule Id="C6328" Action="Warning" />
<Rule Id="C6330" Action="Warning" />
<Rule Id="C6331" Action="Warning" />
<Rule Id="C6332" Action="Warning" />
<Rule Id="C6333" Action="Warning" />
<Rule Id="C6334" Action="Warning" />
<Rule Id="C6335" Action="Warning" />
<Rule Id="C6383" Action="Warning" />
<Rule Id="C6384" Action="Warning" />
<Rule Id="C6385" Action="Warning" />
<Rule Id="C6386" Action="Warning" />
<Rule Id="C6387" Action="Warning" />
<Rule Id="C6388" Action="Warning" />
<Rule Id="C6411" Action="Warning" />
<Rule Id="C6503" Action="Warning" />
<Rule Id="C6504" Action="Warning" />
<Rule Id="C6508" Action="Warning" />
<Rule Id="C6514" Action="Warning" />
<Rule Id="C6517" Action="Warning" />
</Rules>
</RuleSet>
14 changes: 9 additions & 5 deletions include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ SK_ImGui_ProcessRawInput ( _In_ HRAWINPUT hRawInput,
}

// On error, simply return immediately...
if (size == -1)
if (size == ~0U)
return size;

// Input event happened while the window had focus if true, otherwise another
Expand Down Expand Up @@ -1487,14 +1487,18 @@ ImGui_WndProcHandler ( HWND hWnd, UINT msg,
static constexpr GUID GUID_DEVINTERFACE_HID =
{ 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };

if (IsEqualGUID (pDevW->dbcc_classguid, GUID_DEVINTERFACE_HID))
static constexpr GUID GUID_XUSB_INTERFACE_CLASS =
{ 0xEC87F1E3L, 0xC13B, 0x4100, { 0xB5, 0xF7, 0x8B, 0x84, 0xD5, 0x42, 0x60, 0xCB } };

if (IsEqualGUID (pDevW->dbcc_classguid, GUID_DEVINTERFACE_HID) ||
IsEqualGUID (pDevW->dbcc_classguid, GUID_XUSB_INTERFACE_CLASS))
{
bool xinput = false;
bool xinput = IsEqualGUID (pDevW->dbcc_classguid, GUID_XUSB_INTERFACE_CLASS);

if ( pDevW->dbcc_size == sizeof (DEV_BROADCAST_DEVICEINTERFACE_W))
xinput = wcsstr (pDevW->dbcc_name, L"IG_") != nullptr;
xinput |= wcsstr (pDevW->dbcc_name, L"IG_") != nullptr;
else if (pDevA->dbcc_size == sizeof (DEV_BROADCAST_DEVICEINTERFACE_A))
xinput = strstr (pDevA->dbcc_name, "IG_") != nullptr;
xinput |= strstr (pDevA->dbcc_name, "IG_") != nullptr;

if (xinput)
{
Expand Down
46 changes: 35 additions & 11 deletions src/imgui/backends/imgui_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,24 +1996,48 @@ SK_D3D12_RenderCtx::init (IDXGISwapChain3 *pSwapChain, ID3D12CommandQueue *pComm

if (_pDevice.p == nullptr)
{
if ( _pCommandQueue.p != nullptr && SUCCEEDED (
if ( _pCommandQueue.p != nullptr && FAILED (
_pCommandQueue->GetDevice ( IID_PPV_ARGS (&_pDevice.p) )
)
)
)
{
_pSwapChain =
pSwapChain;
return false;
}
}

static auto& rb =
SK_GetCurrentRenderBackend ();
if (_pDevice.p != nullptr)
{
_pSwapChain =
pSwapChain;

static auto& rb =
SK_GetCurrentRenderBackend ();

if (rb.swapchain == nullptr)
if (rb.swapchain == nullptr || rb.swapchain != pSwapChain)
{
// This is unexpected, but may happen if a game destroys its original window
// and then creates a new SwapChain
if (rb.swapchain != nullptr)
{
rb.swapchain = pSwapChain;
rb.device = _pDevice.p;
rb.d3d12.command_queue = _pCommandQueue.p;
rb.api = SK_RenderAPI::D3D12;
SK_LOGi0 (
L"# Transitioning active ImGui SwapChain from %p to %p",
rb.swapchain.p, pSwapChain );

#if 1 // Likley the device is always the same due to D3D12 adapters being singletons
_pDevice = nullptr;
_pCommandQueue = pCommandQueue;

if (_pCommandQueue != nullptr)
{
_pCommandQueue->GetDevice (IID_PPV_ARGS (&_pDevice.p));
}
#endif
}

rb.swapchain = pSwapChain;
rb.device = _pDevice.p;
rb.d3d12.command_queue = _pCommandQueue.p;
rb.api = SK_RenderAPI::D3D12;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/widgets/hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ struct SK_HDR_Preset_s {
store ();
}
}
} static hdr_presets [4] = { { "HDR Preset 0", 0, 160.0_Nits, 80.0_Nits, 100.0_Nits, 0.95f, 1.0f, 0.015f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F1" },
{ "HDR Preset 1", 1, 80.0_Nits, 80.0_Nits, 100.0_Nits, 0.92f, 1.0f, 0.010f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v0.PQBoost0, SK_HDR_PQBoost_v0.PQBoost1, SK_HDR_PQBoost_v0.PQBoost2, SK_HDR_PQBoost_v0.PQBoost3, L"Shift+F2" },
{ "scRGB Native", 2, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.00f, 1.0f, 0.000f, { SK_HDR_TONEMAP_NONE }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F3" },
{ "HDR10 Native", 3, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.00f, 1.0f, 0.000f, { SK_HDR_TONEMAP_HDR10_PASSTHROUGH }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F4" } },
hdr_defaults [4] = { { "HDR Preset 0", 0, 160.0_Nits, 80.0_Nits, 100.0_Nits, 0.95f, 1.0f, 0.015f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F1" },
{ "HDR Preset 1", 1, 80.0_Nits, 80.0_Nits, 100.0_Nits, 0.92f, 1.0f, 0.010f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v0.PQBoost0, SK_HDR_PQBoost_v0.PQBoost1, SK_HDR_PQBoost_v0.PQBoost2, SK_HDR_PQBoost_v0.PQBoost3, L"Shift+F2" },
{ "scRGB Native", 2, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.00f, 1.0f, 0.000f, { SK_HDR_TONEMAP_NONE }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F3" },
{ "HDR10 Native", 3, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.00f, 1.0f, 0.000f, { SK_HDR_TONEMAP_HDR10_PASSTHROUGH }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F4" } };
} static hdr_presets [4] = { { "HDR Preset 0", 0, 160.0_Nits, 80.0_Nits, 100.0_Nits, 0.955f, 1.0f, 0.015f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F1" },
{ "HDR Preset 1", 1, 80.0_Nits, 80.0_Nits, 100.0_Nits, 0.920f, 1.0f, 0.010f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v0.PQBoost0, SK_HDR_PQBoost_v0.PQBoost1, SK_HDR_PQBoost_v0.PQBoost2, SK_HDR_PQBoost_v0.PQBoost3, L"Shift+F2" },
{ "scRGB Native", 2, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.000f, 1.0f, 0.000f, { SK_HDR_TONEMAP_NONE }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F3" },
{ "HDR10 Native", 3, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.000f, 1.0f, 0.000f, { SK_HDR_TONEMAP_HDR10_PASSTHROUGH }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F4" } },
hdr_defaults [4] = { { "HDR Preset 0", 0, 160.0_Nits, 80.0_Nits, 100.0_Nits, 0.955f, 1.0f, 0.015f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F1" },
{ "HDR Preset 1", 1, 80.0_Nits, 80.0_Nits, 100.0_Nits, 0.920f, 1.0f, 0.010f, { SK_HDR_TONEMAP_NONE }, SK_HDR_PQBoost_v0.PQBoost0, SK_HDR_PQBoost_v0.PQBoost1, SK_HDR_PQBoost_v0.PQBoost2, SK_HDR_PQBoost_v0.PQBoost3, L"Shift+F2" },
{ "scRGB Native", 2, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.000f, 1.0f, 0.000f, { SK_HDR_TONEMAP_NONE }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F3" },
{ "HDR10 Native", 3, 80.0_Nits, 80.0_Nits, 100.0_Nits, 1.000f, 1.0f, 0.000f, { SK_HDR_TONEMAP_HDR10_PASSTHROUGH }, -SK_HDR_PQBoost_v1.PQBoost0, SK_HDR_PQBoost_v1.PQBoost1, SK_HDR_PQBoost_v1.PQBoost2, SK_HDR_PQBoost_v1.PQBoost3, L"Shift+F4" } };

BOOL
CALLBACK
Expand Down
12 changes: 9 additions & 3 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5349,8 +5349,6 @@ SK_DetourWindowProc ( _In_ HWND hWnd,
{
SK_LOG0 ( ( L"(?) Active window destroyed, our chicken has no head!" ),
__SK_SUBSYSTEM__ );
game_window.hWnd = 0;
game_window.active = true; // The headless chicken appears very active...

if (GetAncestor (hWnd, GA_ROOT) == game_window.hWnd)
{
Expand All @@ -5359,7 +5357,9 @@ SK_DetourWindowProc ( _In_ HWND hWnd,
extern void SK_Inject_SetFocusWindow (HWND hWndFocus);
SK_Inject_SetFocusWindow (0);

SK_ImGui_WantExit = true;
// It's not clear why this was here, WM_QUIT should be where this is handled...
// of course that message is never dispatched.
//SK_ImGui_WantExit = true;

// Even if we don't exit SK in response to this message, resetting
// temporary display mode changes would be a good idea.
Expand All @@ -5368,6 +5368,12 @@ SK_DetourWindowProc ( _In_ HWND hWnd,
if (config.compatibility.shutdown_on_window_close)
SK_SelfDestruct ();
}

rb.windows.focus.update (0);
rb.windows.device.update (0);

game_window.hWnd = 0;
game_window.active = true; // The headless chicken appears very active...
}
break;

Expand Down

0 comments on commit 211dd1d

Please sign in to comment.