microsoft / microsoft/microsoft-ui-xaml

Application crash when moving/changing state on a Window after calling Close on WebView2 before it's unloaded

Open
#10,219 6 comments 0 reactions 0 assignees View on GitHub
area-WebView bug Regression team-Controls
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

If you call Close on a WebView2 control before the control has been unloaded and change the position of the window (changing Overlapped presenter in our case) the app will crash.

The root cause of this looks like the AppWindow.Changed event is unwired in the Unloaded event and not in the Close method. When the window position changes the NotifyParentWindowPositionChanged is called on the CoreWebViewController which causes an access violation which crashes the application.

I have a crash dump file if needed.

A workaround is to call the Close in the Unloaded event of the WebView2.

### Steps to reproduce the bug

1. Maximize window (OverlappedPresenter.Maximize)
2. Call Close on WebView
3. Restore Window (OverlappedPresenter.Restore)

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

### Windows version

Windows 11 (23H2): Build 22631

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the crash with WinUI 3 and Windows App SDK 1.6.3 using the listed maximize, Close, and restore sequence. Trace the WebView2 lifecycle around AppWindow.Changed, Unloaded, Close, and NotifyParentWindowPositionChanged; done means closing before unload no longer crashes when the window position changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.