Skip to content

Access violation on clicking title bar button #6373

@benstevens48

Description

@benstevens48

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-WindowingTopics related to the Windowing API in Windows App SDK, including AppWindow, presenters, etc.needs-triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions