maui icon indicating copy to clipboard operation
maui copied to clipboard

I have "Cycles detected in layout" exceptions all over my app. How can I debug the .NET MAUI source code?

Open enjoysmath opened this issue 2 years ago • 6 comments

Description

I'm getting this infamous titled error about cycles detected in the layout in many different scenarious on the various pages of my app for a work project. Why does the app have to crash under cycle detection? Shouldn't we be able to toggle this feature off? Why not constrain the size of the window if it causes error for example? Or only display last known good layout. Why not automatically add in scrollbars if the content size is at its full minimum possible? Those are possible workarounds for this bug, supposing I were a developer.

Steps to Reproduce

Just try putting

<Shell.TitleView>
     <Grid Padding="8,0,8,0" Margin="0" HorizontalOptions="FillAndExpand" ColumnDefinitions="Auto,*,Auto">
         <Image Grid.Column="0" HorizontalOptions="Start" Source="app_logo.png" WidthRequest="200">
             <Image.GestureRecognizers>
                 <TapGestureRecognizer x:Name="avatarTapGesture"
                     Command="{Binding GoHomeCommand}"/>
             </Image.GestureRecognizers>
         </Image>
         <Label Grid.Column="1" HorizontalOptions="Center" HorizontalTextAlignment="Center"
                VerticalTextAlignment="Center" Text="Dashboard | Settings" Style="{StaticResource LargeLabel}"/>
         <Button Grid.Column="2" HorizontalOptions="End" VerticalOptions="Center" Text="Sign Out" Style="{StaticResource ButtonOutline}"
                 Command="{Binding SignOutCommand}" Margin="100,0,0,0"/>
     </Grid>
 </Shell.TitleView>

At the top of a Content Page. Your page will work fine until you shrink it down to minimum size and then back up, the app will crash with an unhandled exception of "Layout detected a cycle. Could not complete layout" or some other "Cycle detected in layout exception."

Link to public reproduction project repository

(Private)

Version with bug

6.0.312

Last version that worked well

6.0.312

Affected platforms

Windows

Affected platform versions

Windows 10

Did you find any workaround?

No workaround except to completely delete something. Sometimes a page will work great until you add a 4th column in a Grid layout. Then cycles get detected.

I would like to fix this problem because it's in other parts of my site as well. It's not just one layout's problem. For instance I tried replacing about 30 vert and horizontal stack layouts with equivalent Grids and the problem got worse. I've tried using Flex Layouts and while you'd think that would solve the problem, it seems to only make it worse. Scroll View for large content? Forget about it. Cycle error. Please show me where the documentation is on how to install .NET MAUI from source into VS.

Thank you!

Relevant log output

"A cycle occured while laying out the GUI."

"Layout cycle detected. Layout could not complete."

enjoysmath avatar Feb 19 '23 03:02 enjoysmath

I am surprised that as declarative as XAML we can still get this... html never have this problem

Xyncgas avatar Feb 19 '23 12:02 Xyncgas

@Xyncgas AFAIK this has to do with the underlying controls and how they are rendered by WinUI. Depending on the conditions MAUI presents the controls to WinUI to render, WinUI throws its hands up and says "I can't do it that way." And either requires us change MAUI to a better way to render it, or WinUI to fix something that could cause the layout to cycle.

It has nothing to do with XAML, you can write the same code as C# Markup and it will do the same thing.

drasticactions avatar Feb 20 '23 04:02 drasticactions

Hi @enjoysmath. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Feb 20 '23 15:02 ghost

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

ghost avatar Feb 24 '23 16:02 ghost

Version with bug 6.0.312

Have you tried a more recent version?

hartez avatar Feb 24 '23 19:02 hartez

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

ghost avatar Feb 28 '23 20:02 ghost