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

[Android] Crash when replacing a Layout (Grid or Stacked) in an existing layout #21338

Open
czuck opened this issue Mar 20, 2024 · 2 comments
Open
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter high It doesn't work at all, crashes or has a big impact. platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@czuck
Copy link

czuck commented Mar 20, 2024

Description

On Android when the new Layout is added to the existing layout the following error occurs:
image

This works on iOS

Steps to Reproduce

Create a file > new Net Maui App. Change the MainPage to:

    <Grid x:Name="OuterGrid"
          RowDefinitions="*, Auto, *"
          ColumnDefinitions="*, Auto,*">
        <Grid x:Name="InnerGrid"
              Grid.Column="1"
              Grid.Row="1">
            <Label x:Name="MyLabel" 
                   Text="My Label"
                   Grid.Row="0"></Label>
            
        </Grid>
    </Grid>
    <!--<VerticalStackLayout x:Name="OuterLayout">
        <VerticalStackLayout x:Name="InnerLayout">
            <Label x:Name="MyLabel" 
                   Text="My Label"></Label>
        </VerticalStackLayout>
    </VerticalStackLayout>-->
        public MainPage()
        {
            InitializeComponent();
            SizeChanged += (sender, e) => SetOrientation(sender, e, this);
        }

        private void SetOrientation(object sender, EventArgs e, Page p)
        {
            OuterGrid.Remove(InnerGrid);
            InnerGrid = new Grid { { MyLabel, 0, 0 } };
            OuterGrid.Add(InnerGrid, 1, 1);

            //OuterLayout.Remove(InnerLayout);
            //InnerLayout = new VerticalStackLayout { Children = { MyLabel } };
            //OuterLayout.Add(InnerLayout);
        }

and run it. The error occurs for both the Grid code and the commented out VerticalStackLayout code.
If the line in SetOrientation that creates the new Layout Control is commented out the error does not occur. This isn't a workaround because in my use case I'm changing the Inner layout based on the orientation.
Stepping through the SetOrientation code the InnerGrid is successfully removed from the children of the outer grid by the Remove() command - OuterGrid.Children.Count goes from 1 to 0. It is also successfully added back at the Add command - OuterGrid.Children.Count goes from 0 back to 1 - as the error is thrown; it's as if it's trying to add the InnerGrid twice.

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Tested on Android 12.1 and 14.0

Did you find any workaround?

If I don't remove and re-add the

Relevant log output

No response

@czuck czuck added the t/bug Something isn't working label Mar 20, 2024
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Mar 21, 2024
@Zhanglirong-Winnie
Copy link
Collaborator

Verified this issue with Visual Studio 17.10.0 Preview 2(8.0.10). Can repro on android platform with above code.

@czuck
Copy link
Author

czuck commented Mar 21, 2024

Recreated with 8.0.14 as well.

@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Mar 29, 2024
@jsuarezruiz jsuarezruiz added the high It doesn't work at all, crashes or has a big impact. label Jun 4, 2024
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 4, 2024
@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter high It doesn't work at all, crashes or has a big impact. platform/android 🤖 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

5 participants