Skip to content

[PowerToys] Guard TitleBar windows against an empty window title (startup fault) - #49069

Merged
niels9001 merged 2 commits into
microsoft:mainfrom
crutkas:user/crutkas/fix-envvars-titlebar-failfast
Jul 2, 2026
Merged

[PowerToys] Guard TitleBar windows against an empty window title (startup fault)#49069
niels9001 merged 2 commits into
microsoft:mainfrom
crutkas:user/crutkas/fix-envvars-titlebar-failfast

Conversation

@crutkas

@crutkas crutkas commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Guard PowerToys' WinUI windows against an empty native window title, so the WinUI TitleBar control can't read an empty title during startup and fault the process. This fixes a class of bugs like #48547

Background

Spotted while reading through the Environment Variables MainWindow startup path. The WinUI TitleBar control (used with ExtendsContentIntoTitleBar) reads the owning window's AppWindow.Title during a deferred layout pass (OnApplyTemplateUpdateTitle). When the native window title is empty at that instant, the windowing layer can fault while resolving the title and terminate the process during startup.

The native title ends up empty in two ways:

  1. The title is computed from ResourceLoader.GetString(...), which returns an empty string (it doesn't throw) when the resource map can't be resolved at runtime.
  2. The window sets AppWindow.Title only later, not before the title bar's first layout.

Windows fixed

Every PowerToys window that hosts the TitleBar control:

Window Fix
Environment Variables Non-empty fallback for the resource-based title
Hosts Non-empty fallback for the resource-based title
File Locksmith Non-empty fallback for the resource-based title
Shortcut Guide Non-empty fallback for the resource-based title
Settings — shortcut-conflict window Non-empty fallback for the resource-based title
Registry Preview Set AppWindow.Title to the app name in the constructor (previously only set later in UpdateWindowTitle)
Keyboard Manager Editor No change — already sets a hardcoded non-empty Title

Risk

Very low. The only behavior change is that a previously-empty title becomes a non-empty fallback; the normal (resource-resolved) paths are unchanged.

Validation

Each affected project builds clean (x64 | Release): EnvironmentVariables, Hosts, FileLocksmithUI, ShortcutGuide.Ui, RegistryPreview, PowerToys.Settings.

Related

Root cause write-up (windowing/WinUI side): microsoft/microsoft-ui-xaml#11214.


ADO: https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/62685601/

crutkas and others added 2 commits July 1, 2026 12:03
… title-bar startup fault

While reading through the Environment Variables window startup path I noticed the
window title comes straight from ResourceLoader.GetString(...) with no fallback.
ResourceLoader.GetString returns an empty string when the resource map can't be
resolved at runtime, which leaves both Window.Title and the WinUI TitleBar
control's Title empty.

The WinUI TitleBar control reads the owning window's AppWindow.Title during a
deferred layout pass. When the native window title is empty at that instant, the
windowing layer can fault while resolving the title and terminate the process
during startup.

Guard the computed title with a non-empty product-name fallback so the native
window title is always populated before the title bar reads it. The fallback is
intentionally a plain string rather than a localized resource because it only
runs when the resource loader itself failed to resolve.

---

ADO: https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/62685601/

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dow title

Follow-up to the Environment Variables fix in this PR: the same WinUI TitleBar
startup fault applies to every window that hosts the TitleBar control with an
extended title bar and can let the native window title be empty when the control
first reads it during a deferred layout pass.

Applied the same non-empty-title guard to the other affected windows:

- Hosts, File Locksmith, Shortcut Guide, and Settings' shortcut-conflict window:
  their titles come from ResourceLoader.GetString(...), which returns an empty
  string when the resource map can't be resolved at runtime. Fall back to a
  non-empty product name.
- Registry Preview: it only set AppWindow.Title later (in UpdateWindowTitle, on
  file load), leaving the native window title empty during startup. Set it to
  the app name in the constructor.

Keyboard Manager Editor already sets a hardcoded non-empty Title, so it needs no
change.

Built each affected project (Hosts, FileLocksmithUI, ShortcutGuide.Ui,
RegistryPreview, PowerToys.Settings) in Release x64 with no errors.

---

ADO: https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/62685601/

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@crutkas
crutkas force-pushed the user/crutkas/fix-envvars-titlebar-failfast branch from 4121a1e to b9643f2 Compare July 1, 2026 19:05
@crutkas crutkas changed the title [EnvironmentVariables] Guard against an empty window title to avoid a title-bar startup fault [PowerToys] Guard TitleBar windows against an empty window title (startup fault) Jul 1, 2026
@crutkas crutkas added the 0.101 label Jul 1, 2026
@niels9001
niels9001 enabled auto-merge (squash) July 2, 2026 12:12
@niels9001
niels9001 merged commit de48594 into microsoft:main Jul 2, 2026
8 checks passed
@jiripolasek jiripolasek added Product-Shortcut Guide Refers to the Shortcut Guide PowerToy Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager Product-Settings The standalone PowerToys Settings application Product-Hosts File Editor Refers to the Hosts file editor Product-Registry Preview Refers to the Registry Preview PowerToy labels Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.101 Product-Environment Variables Refers to Environment Variables PowerToys Product-Hosts File Editor Refers to the Hosts file editor Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager Product-Registry Preview Refers to the Registry Preview PowerToy Product-Settings The standalone PowerToys Settings application Product-Shortcut Guide Refers to the Shortcut Guide PowerToy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants