dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

[Android] Infinite arrange loop from VerticalStackLayoutManager.ArrangeChildren #21798

Open Larhei opened 7 months ago

Larhei commented 7 months ago

Description

When Prototyping something like a FlowDocument i came across an infinite arrange cycle that seems to be caused by border Stroketickness.

   <StackLayout>
       <Border>
           <WebView Background="Red">
               <WebView.Source>
                   <HtmlWebViewSource>
                       <HtmlWebViewSource.Html>
                           <![CDATA[
Some HTML
]]>
                       </HtmlWebViewSource.Html>
                   </HtmlWebViewSource>
               </WebView.Source>
           </WebView>
       </Border>
   </StackLayout>

After the html is rendered the Webview gets resized, forcing a layout pass. And than the isse starts kicking in see the Webview growing Recording

I guess this is a rounding issue in the calculation when things get close to epsilon...

Steps to Reproduce

  1. Checkout Repository
  2. Run it

Link to public reproduction project repository

https://github.com/Larhei/Maui-Issues/tree/main/LayoutCycle

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

Setting StrokeThickness on Border to 0 stops the loop.

Relevant log output

>   0xA in LayoutCycle.CustomBorder.OnSizeAllocated at C:\Users\lh\source\repos\Maui-Issues\LayoutCycle\CustomBorder.cs:8,9 C#
    0x3 in Microsoft.Maui.Controls.VisualElement.SizeAllocated at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1319,64   C#
    0x4E in Microsoft.Maui.Controls.VisualElement.UpdateBoundsComponents at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1702,4  C#
    0x11 in Microsoft.Maui.Controls.VisualElement.set_Frame at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1729,5   C#
    0x8 in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1845,4  C#
    0x2 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1834,4 C#
    0x78 in Microsoft.Maui.Layouts.VerticalStackLayoutManager.ArrangeChildren at D:\a\_work\1\s\src\Core\src\Layouts\VerticalStackLayoutManager.cs:64,5 C#
    0x7 in Microsoft.Maui.Controls.StackLayoutManager.ArrangeChildren at D:\a\_work\1\s\src\Controls\src\Core\Layout\StackLayoutManager.cs:37,4 C#
    0x7 in Microsoft.Maui.Controls.Layout.CrossPlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\Layout\Layout.cs:359,4   C#
    0x11 in Microsoft.Maui.Platform.LayoutViewGroup.CrossPlatformArrange at D:\a\_work\1\s\src\Core\src\Platform\Android\LayoutViewGroup.cs:62,4    C#
    0x2B in Microsoft.Maui.Platform.LayoutViewGroup.OnLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\LayoutViewGroup.cs:111,4   C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3670,4 C#
    0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:444,5   C#
    0xF in Java.Interop.JniNativeMethods.CallNonvirtualVoidMethodA at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:18296,4  C#
    0x73 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20825,4    C#
    0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6    C#
    0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3384,5   C#
    0xD4 in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at D:\a\_work\1\s\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:133,4  C#
    0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutViewGroup>.PlatformArrange at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.Android.cs:15,4  C#
    0x1F in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1846,4 C#
    0x2 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:1834,4 C#
    0x5A in Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContent at D:\a\_work\1\s\src\Core\src\Layouts\LayoutExtensions.cs:182,4 C#
    0x9 in Microsoft.Maui.Controls.ContentPage.Microsoft.Maui.ICrossPlatformLayout.CrossPlatformArrange at D:\a\_work\1\s\src\Controls\src\Core\ContentPage\ContentPage.cs:92,4 C#
    0x11 in Microsoft.Maui.Platform.ContentViewGroup.CrossPlatformArrange at D:\a\_work\1\s\src\Core\src\Platform\Android\ContentViewGroup.cs:56,4  C#
    0x23 in Microsoft.Maui.Platform.ContentViewGroup.OnLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\ContentViewGroup.cs:99,4  C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3670,4 C#
    0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:444,5   C#
    0xF in Java.Interop.JniNativeMethods.CallNonvirtualVoidMethodA at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:18296,4  C#
    0x73 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20825,4    C#
    0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6    C#
    0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3384,5   C#
    0x23 in Microsoft.Maui.Controls.Platform.Compatibility.ShellPageContainer.OnLayout at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellPageContainer.cs:47,5  C#
    0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:3670,4 C#
    0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:444,5   C#
Zhanglirong-Winnie commented 7 months ago

Verified this issue with Visual Studio 17.10.0 Preview 3(8.0.20). Can repro on android platform whit sample project.

PureWeen commented 6 months ago

@Zhanglirong-Winnie can you test again against latest nightly?