Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WindowsAppSDK1.4 ]Exception on Close() ( AppWindow is set as parent of Xaml Window ) #9203

Closed
AnnaSusan opened this issue Jan 4, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@AnnaSusan
Copy link

AnnaSusan commented Jan 4, 2024

Issue is only in WindowsAppSDK1.4 , not in 1.3.

An AppWindow is created and is made as a parent to XamlWindow. On button( of XamlWindow) click , Close() is called. Which resulted in exception.

Steps to reproduce the bug

A simple WinUI3 ( WinRT c++ ) app is created. WindowsAppSDK1.4 is created.
By default a xaml window is there ( MainWindow.xaml ). On Button click of MainWindow, another window is created.

void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
    {
            winrt::Microsoft::UI::Windowing::AppWindow AppWindows(nullptr);
            AppWindows = winrt::Microsoft::UI::Windowing::AppWindow::Create();
            HWND hAppWnd = (HWND)AppWindows.Id().Value;
            HWND hMsgWnd{ 0 };
            auto k = make<BlankWindow>();    
            hMsgWnd = (HWND)k.AppWindow().Id().Value;
           ::SetParent(hMsgWnd, hAppWnd);
           // k.AppWindow().
            AppWindows.Show();
            k.Activate();   
    }

In the above code an AppWindow is created, a Xaml window is created.
AppWindow is set as parent to Xaml window.
::SetParent(hMsgWnd, hAppWnd);

BlankWindow

A simple window added to project.

<Window
    x:Class="App5.BlankWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App5"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" >

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="DimGray" >
        <Button x:Name="myButton" Click="myButton_Click" Foreground="Red">Click Me</Button>
    </StackPanel>
</Window>
void BlankWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
    Close();
}

On button click on BlankWindow, Close is called, which creates exception/crash.
Exception thrown at 0x00007FFF49751328 (Microsoft.ui.xaml.dll) in App5.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

[CallStack]

Microsoft.ui.xaml.dll!DirectUI::WindowChrome::SetTitleBar(ABI::Microsoft::UI::Xaml::IUIElement * titleBar=0x0000000000000000) Line 87	C++
 Microsoft.ui.xaml.dll!DirectUI::DesktopWindowImpl::SetTitleBarImpl(ABI::Microsoft::UI::Xaml::IUIElement * pTitleBar=0x0000000000000000) Line 1285	C++
 [Inline Frame] Microsoft.ui.xaml.dll!DirectUI::Window::SetTitleBarImpl(ABI::Microsoft::UI::Xaml::IUIElement *) Line 846	C++
 Microsoft.ui.xaml.dll!DirectUI::WindowGenerated::SetTitleBar(ABI::Microsoft::UI::Xaml::IUIElement * pTitleBar=0x0000000000000000) Line 374	C++
Microsoft.ui.xaml.dll!DirectUI::DesktopWindowImpl::CloseImpl() Line 451	C++
 [Inline Frame] Microsoft.ui.xaml.dll!DirectUI::Window::CloseImpl() Line 287	C++
 Microsoft.ui.xaml.dll!DirectUI::WindowGenerated::Close() Line 247	C++
App5.exe!winrt::impl::consume_Microsoft_UI_Xaml_IWindow<winrt::App5::implementation::BlankWindow>::Close() Line 4604	C++

If we didn't made AppWindow as parent to BlankWindow, Close works fine.

Expected behavior

No response

Screenshots

NuGet package version

None

Windows version

No response

Additional context

No response

@AnnaSusan AnnaSusan added the bug Something isn't working label Jan 4, 2024
Copy link

github-actions bot commented Jan 4, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 4, 2024
@AnnaSusan
Copy link
Author

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

I don't think issue is same as above mentioned links.

@DarranRowe
Copy link

DarranRowe commented Jan 4, 2024

The issue in general here is that a window that is written as a top level window may not function correctly as a child window. Microsoft.UI.Xaml.Window has no means of creating the window as a child, which means that this scenario is not supported. This does have an effect, for example, broadcast messages are only ever sent to top level windows. Changing the parent of a window is also problematic in general. The child window has to be aware of this kind of thing in order to work.

To put it simply, WinUI 3 does not support the main window being set as a child window, it never did. The fact that it worked in earlier versions of the Windows App SDK releases is just luck. There is also a bug report that describes this same layout somewhere, but it was stated that this was by design. I'll see if I can find that.

--Edit--

Right, #8900 is what I was thinking of.

@AnnaSusan
Copy link
Author

Ok. Understood. Thank you for explanation.

@bpulliam
Copy link
Contributor

bpulliam commented Jan 5, 2024

Resolving as dup of #8900

@bpulliam bpulliam closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the needs-triage Issue needs to be triaged by the area owners label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants