microsoft / microsoft/WindowsAppSDK

Access violation on clicking title bar button

Open
#6,373 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Windowing needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

Describe the bug

It turns out that if you put a button directly below one of the title bar buttons (minimize or close), it is possible to hover over both that button and the title bar button at the same time (this is the first minor bug). Secondly, if the button's click handler changes the window presenter to fullscreen, this causes an access violation crash in Microsoft.UI.Windowing.Core.dll. The stack trace is below. I think it may only occur if the title bar color bas been customized. I've also provided a minimal repo under 'Septs to reproduce the bug'.

Exception thrown at 0x00007FF998CBE0B5 (Microsoft.UI.Windowing.Core.dll) in TestTitleButtonCrash.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Microsoft.UI.Windowing.Core.dll!CTitleBar::UpdateButtonState(enum CTitleBar::TitleBarControl,bool)	Unknown
 	Microsoft.UI.Windowing.Core.dll!CTitleBar::UpdateHoverPressState(enum CTitleBar::TitleBarControl)	Unknown
 	Microsoft.UI.Windowing.Core.dll!CTitleBar::OnHovered(struct Microsoft::UI::Input::INonClientPointerEventArgs *,bool)	Unknown
 	Microsoft.UI.Windowing.Core.dll!CTitleBar::OnPointerReleased(struct Microsoft::UI::Input::IInputNonClientPointerSource *,struct Microsoft::UI::Input::INonClientPointerEventArgs *)	Unknown
Steps to reproduce the bug

Create the a blank C# WinUI packaged app and replace the MainWindow with the following. Then place the mouse cursor in a position where it hovers over both the minimize button and the in-app fullscreen button (the fullscreen button will be non-aqua at this point). (I am on display scaling 125% - this could be needed to get this to happen). Now click, and observe the crash. From experimenting it appears that the in-app button click handler is called first before the title bar's button mouse up handler (which crashes).

<?xml version="1.0" encoding="utf-8"?>
<Window x:Class="TestTitleButtonCrash.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestTitleButtonCrash">
    <Grid>
        <Button Name="fullscreenButton" HorizontalAlignment="Right" VerticalAlignment="Top" Width="200" Height="100" Margin="0" Background="Aqua" Content="Fullscreen" Click="fullscreenButton_Click"></Button>
    </Grid>
</Window>
using Microsoft.UI;
using Microsoft.UI.Xaml;

namespace TestTitleButtonCrash {
    public sealed partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            AppWindow.TitleBar.BackgroundColor = Colors.Blue;
        }
        private void fullscreenButton_Click(object sender, RoutedEventArgs e) {
            if (AppWindow.Presenter.Kind == Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen) {
                AppWindow.SetPresenter(Microsoft.UI.Windowing.AppWindowPresenterKind.Overlapped);
            } else {
                AppWindow.SetPresenter(Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen);
            }
        }
    }
}
Expected behavior

No response

Screenshots

No response

NuGet package version

1.8.260317003

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 LTSC (26100, June Update)

IDE

No response

Additional context

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal packaged C# WinUI app in MainWindow.xaml and MainWindow.xaml.cs, using the reported title-bar color, button placement, and 125% scaling. Reproduce the overlapping hover state and toggle fullscreen from fullscreenButton_Click, then inspect the Microsoft.UI.Windowing.Core stack trace. Done means the title-bar interaction no longer produces the access violation and the overlapping-button behavior is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.