From 65bb40d1b90a662b4392f3d03ebc1db83f85684a Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Thu, 25 Jun 2026 18:15:05 +0200 Subject: [PATCH] [Shortcut Guide] Guard against null AppWindow in SetWindowPosition (#48773) When the Windows section is selected, the Hide -> Activate -> BringToFront reentrancy can re-enter SetWindowPosition while the main window's own AppWindow is transiently null. The first WinUIEx size access (MaxHeight -> get_Height) then dereferences the null AppWindow and throws a NullReferenceException, leaving the overlay mispositioned on Windows 10. Skip the positioning pass when AppWindow is null; a later AppWindow.Changed or Activated event reruns it once the window settles. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ShortcutGuideXAML/MainWindow.xaml.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs b/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs index f7d9a400be4a..bb613d26983e 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs +++ b/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs @@ -239,6 +239,16 @@ private void SetWindowPosition() { try { + // During the reentrant Hide -> Activate -> BringToFront chain triggered from + // section selection, this window's own AppWindow can briefly be null. Any WinUIEx + // size access below (e.g. MaxHeight -> get_Height) would dereference it and throw an + // NRE from inside WinUIEx (issue #48773). Skip this pass and keep the previous layout; + // a later AppWindow.Changed / Activated event reruns this once the window settles. + if (AppWindow is null) + { + return; + } + if (!this._hasMovedToRightMonitor) { NativeMethods.GetCursorPos(out NativeMethods.POINT lpPoint);