[Shortcut Guide] Guard against null AppWindow in SetWindowPosition#48870
Draft
niels9001 wants to merge 1 commit into
Draft
[Shortcut Guide] Guard against null AppWindow in SetWindowPosition#48870niels9001 wants to merge 1 commit into
niels9001 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the residual
NullReferenceExceptioninMainWindow.SetWindowPosition()reported in #48773 (seen on Windows 10, even after the 0.100.1 hotfix #48481).Background
#48481 stopped the original hard crash by adding a try/catch and null-guarding
App.TaskBarWindow?.AppWindow. But a second NRE remained. From the reporter's 0.100.1 log:Root cause
Selecting the Windows section (the only common one carrying the
<TASKBAR1-9>section) runsApp.TaskBarWindow.Hide() → Activate() → BringToFront(). That reentrancy re-entersSetWindowPosition()while the main window's ownAppWindowis transiently null. The earlier fix only guarded the taskbar window'sAppWindow, not the main window's. The first size access in the method (MaxHeight = newHeight) makes WinUIEx readget_Height()on the nullAppWindow→ NRE. The exception is now caught (post-#48481), so it no longer hard-crashes, but the overlay is left mispositioned and the section appears broken on Windows 10.Change
Early-return from
SetWindowPosition()when the window's ownAppWindowis null. This is safe: a laterAppWindow.Changed/Activatedevent reruns the positioning once the window settles, so the final layout is still applied — only the bogus reentrant pass is dropped. The existing try/catch remains as a backstop.Validation
ShortcutGuide.Uibuilds clean (x64 Release, exit 0).Notes
The long-term cleanup is the dual-window → single-overlay rewrite in #48683, which removes this code path entirely. This is the small, low-risk hotfix for the 0.100.x line.