From f3db42960854612b2842877c892cb248f733a377 Mon Sep 17 00:00:00 2001 From: Essam Date: Wed, 26 Aug 2026 07:52:43 +0200 Subject: [PATCH] Guard island input site lookup during shutdown CDependencyObject::GetElementIslandInputSite() called CCoreServices::GetInputServices()->GetPrimaryRegisteredIslandInputSite() without checking the result of GetInputServices(). By the time a focused TextBox is torn down during framework shutdown the input services are already gone, so the call runs on a null "this" and faults while reading m_islandInputSiteRegistrations. Null-check core services and input services and return nullptr instead. Every caller already funnels the result through CInputServices::GetUnderlyingInputHwndFromIslandInputSite(), which is declared _In_opt_ and null-checks its argument, so "no island input site" is already an expected result. Carries forward the fix proposed by @jonwis in #11063, rebased onto the current dxaml/ layout. --- dxaml/xcp/core/core/elements/depends.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dxaml/xcp/core/core/elements/depends.cpp b/dxaml/xcp/core/core/elements/depends.cpp index de2b7ecd9f..b7b5e97809 100644 --- a/dxaml/xcp/core/core/elements/depends.cpp +++ b/dxaml/xcp/core/core/elements/depends.cpp @@ -316,7 +316,7 @@ wrl::ComPtr CDependencyObject::GetElementIsla return spPopup->GetIslandInputSite(); } - if (coreServices->HasXamlIslandRoots()) + if (coreServices && coreServices->HasXamlIslandRoots()) { // If this element is in a XamlIslandRoot tree, return the IslandInputSite for that island. auto root = coreServices->GetRootForElement(this); @@ -329,7 +329,18 @@ wrl::ComPtr CDependencyObject::GetElementIsla } // By default, return the primary IslandInputSite that was registered with InputServices on startup. - return coreServices->GetInputServices()->GetPrimaryRegisteredIslandInputSite(); + // During shutdown the core services or the input services may already be torn down, in which case + // there is no island input site to return. Callers already treat a null result as "no input site" - + // see the _In_opt_ contract on CInputServices::GetUnderlyingInputHwndFromIslandInputSite. + if (coreServices) + { + if (auto inputServices = coreServices->GetInputServices()) + { + return inputServices->GetPrimaryRegisteredIslandInputSite(); + } + } + + return nullptr; } HWND CDependencyObject::GetElementPositioningWindow()