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

[Windows]Repeated navigation page crash #18441

Closed
BaY1251 opened this issue Oct 31, 2023 · 4 comments
Closed

[Windows]Repeated navigation page crash #18441

BaY1251 opened this issue Oct 31, 2023 · 4 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-navigation NavigationPage platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@BaY1251
Copy link
Contributor

BaY1251 commented Oct 31, 2023

Description

When there are many page elements, repeatedly navigating the interface can cause a crash

NO exception, Just crash

ANR_WINDOWS

First report on #18331,Android platform. To prevent misunderstandings, create a new issue for the Windows platform

Steps to Reproduce

下载 https://github.com/BaY1251/MauiDebug.git
打开 /ANR/ANR.sln 编译生成工程,并运行.
点击 Shell, 反复切换Home和Sec界面,约10次后,问题复现

#translate

Download https://github.com/BaY1251/MauiDebug.git
Open /ANR/ANR.sln to compile and generate a project
Running

Click on Shell and repeatedly switch between the Home and Sec interfaces. After about 10 times, the problem reappear

Link to public reproduction project repository

https://github.com/BaY1251/MauiDebug.git

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows10-22H2 net8.0-windows10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

@BaY1251 BaY1251 added the t/bug Something isn't working label Oct 31, 2023
@drasticactions
Copy link
Contributor

I don't think your issue has to do with Navigation. Your App UI (A CollectionView with bindable layouts embedded) is quite intense and, on my machine, uses around 700 MBs just opening it and fully screening it on the main page alone. Scrolling down will cause the same WinUI exception you're seeing by navigation. You're also navigating to the same page instance, but removing and adding your item source. So you're not navigating to anything; it's the same page.

Looking at the debugger tooling (and turning off XAML Hot Reload) and scrolling through the list, it seems that Setter Specificity continually adds items to its list and doesn't remove them. For example, changing your app UI to

<CollectionView SelectionMode="Single"
				ItemsSource="{Binding ItemList}">
	<CollectionView.ItemTemplate>
		<DataTemplate x:DataType="local:Item">
			<Grid RowSpacing="0"
				  RowDefinitions="Auto,1"
				  ColumnDefinitions="120,*,120,64">
                <Label Text="{Binding Name}"
					   FontSize="24"
					   WidthRequest="120"
					   VerticalOptions="Center"
					   HorizontalTextAlignment="Center" />
            </Grid>
		</DataTemplate>
	</CollectionView.ItemTemplate>
</CollectionView>

and scrolling through the list,

image

The count and memory size seems to, generally, increase all the time. It could be that your app UI as designed, on top of possible memory issues with things like setter specificity, could be causing the problem.

CC @jonathanpeppers @StephaneDelcroix

@BaY1251
Copy link
Contributor Author

BaY1251 commented Oct 31, 2023

@drasticactions 3Q ,yes!, Repeated Invoke Clear and Add can also cause crash

@Eilon Eilon added the area-navigation NavigationPage label Nov 8, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Nov 9, 2023
@XamlTest
Copy link

XamlTest commented Nov 9, 2023

Verified this on Visual Studio Enterprise 17.8.0 Preview 7.0(8.0.0-rc.2.9530). Repro on Windows 11 with below Project:
ANR.zip

@PureWeen
Copy link
Member

Duplicate of #22790

@PureWeen PureWeen marked this as a duplicate of #22790 Nov 18, 2024
Foda added a commit that referenced this issue Nov 19, 2024
### Description of Change

Fixes a long-standing crash when navigating pages:

1. Manually clear the `ContentPresenter.Content` property.

When navigating pages it was discovered that the `Content` property of
the `ContentPresenter` sometimes was not being detached from the parent
`ContentPresenter` (the `ContentPresenter` itself does detach from the
Page). A workaround for this was to manually clear the `Content`
property.

**The actual cause of this bug:** I suspect that something causing the
lifecycle tracking to be messed up. I'm still not sure what this is, but
for now this will help our customers more than nothing.

## Workaround

The following can be used as a workaround. Place it in the `Loaded`
event for your `AppShell`:

```csharp
private void AppShell_Loaded(object? sender, EventArgs e)
{
    Loaded -= AppShell_Loaded;

#if WINDOWS
    if (Handler != null && Handler.PlatformView is ShellView shellView &&
        shellView.Content is MauiNavigationView nv &&
        nv.Content is Microsoft.UI.Xaml.Controls.Frame frame)
    {
        frame.Navigating += (s, e) =>
        {
            if (frame.Content is Microsoft.UI.Xaml.Controls.Page page)
            {
                page.Unloaded += PageUnloaded;

                void PageUnloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
                {
                    page.Unloaded -= PageUnloaded;
                    if (page.Content is Microsoft.UI.Xaml.Controls.ContentPresenter presenter)
                    {
                        presenter.Content = null;
                    }
                };
            }
        };
    }
#endif
}
```

### Issues Fixed

Fixes #22790 #18441 #22131
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-navigation NavigationPage platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants