microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Layout cycle detected (crash) for some list view sizes when scrolling to end of listview

Open wbokkers opened this issue 3 years ago • 43 comments

Describe the bug

I have a list view with group headers and a data template that had no issues in UWP and WinUI 3 WinAppSDK 0.8.

In WinAppSDK 1.0 Preview 3, when scrolling to the end of the list view, I get a layout cycle detected exception. But this is only the case when the listview is of a particular size. Most sizes work fine, though. The size for which the crash happens probably depends on the listview contents, but I am not sure about that.

Steps to reproduce the bug (crash on user interaction)

This issue can be reproduced using this test control: https://gist.github.com/wbokkers/4a07fedfb99d49d4b8e8ff62971d4eb8

  1. Use the test control in a WinUI 3 WASDK 1.0 project.
  2. Click on the Next Seed button. This will choose random content and list box sizes for each seed.
  3. See when the app crashes. (most of the time it crashes on seed 9, sometimes it skips 9 and crashes on larger seed)

NOTE: Most of the time the app crashes right away for seed 9. Sometimes you need to scroll up and down using the touch pad to get the exception.

Reproduce using less code/XAML (crash on load)

The issue can be reproduced with even less and simpler code: https://gist.github.com/wbokkers/011011af9bf95066967bd4998dca9d77

  1. Use this test control in a WinUI WASDK 1.0 project.
  2. Show the control.
  3. Crash

(For non-crashing situations: change the initial _seed or the listview height in the source code)

Expected behavior

There should be no layout cycle detected exception.

NuGet package version

WinUI 3 - Windows App SDK 1.0 Preview 3

Device form factor

Desktop

Windows version

May 2021 Update (19043)

wbokkers avatar Nov 02 '21 13:11 wbokkers

image

wbokkers avatar Nov 04 '21 12:11 wbokkers

@RBrid and @codendone FYI

StephenLPeters avatar Nov 04 '21 23:11 StephenLPeters

This issue is happening all over the place where I am using listviews. It also happens for lists without group headers. It really needs to be fixed in 1.0 for the product to be stable.

wbokkers avatar Nov 12 '21 13:11 wbokkers

Any news on this issue that is blocking our project for weeks now? @gabbybilka, @marb2000, @ryandemopoulos, @SavoySchuler

wbokkers avatar Nov 24 '21 10:11 wbokkers

@wbokkers is this still occurring in 1.0?

gabbybilka avatar Nov 24 '21 17:11 gabbybilka

@gabbybilka Yes, it occurs mainly in 1.0. It is a very frequent crash. I think I have seen this occur in 0.8 as well, but only a couple of times.

wbokkers avatar Nov 24 '21 17:11 wbokkers

I added a new way to reproduce this issue. It's just a matter of using the test control to immediately crash the app. There's nothing wrong with my code. Using most other list view heights and contents will work as expected. But it's just happening way too often in real world scenario's.

wbokkers avatar Nov 24 '21 18:11 wbokkers

@gabbybilka Any news on this and other open issues? The silence is deafening. 🦻

wbokkers avatar Dec 03 '21 08:12 wbokkers

It's getting into an infinite loop where layout A is triggering a response to change layout to B, and that's triggering a response to change layout to A, B, A, ... until it hits the max layout count. Certainly that's not supposed to happen, but it appears to be an issue in the ScrollBar track layout code getting triggered by ItemsStackPanel.ItemsUpdatingScrollMode; removing that stops the cycle:

<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <ItemsStackPanel VerticalAlignment="Bottom" ItemsUpdatingScrollMode="KeepLastItemInView" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

MikeHillberg avatar Dec 07 '21 00:12 MikeHillberg

@MikeHillberg Thanks for locating what's causing this issue. Unfortunately, removing ItemsUpdatingScrollMode is not an option. I need to keep the last item in view as soon as one arrives in the list view. (it's a chat-like experience).

Removing ItemsUpdatingScrollMode and using my own code to scroll to the last item will also trigger a layout cycle (less frequent) and I can't always get it to scroll down completely using this method. So there's no good workaround.

It would be great if this issue could be resolved in the 1.0 release as a quality update.

(edit: tried to use a less irritated and impatient tone.. not my forte)

wbokkers avatar Dec 07 '21 08:12 wbokkers

@MikeHillberg @gabbybilka Any news on the status?

This is the crash report of te latest version of our app, with Windows App SDK 1.0. I can see 10 crashes in 24 hours due to this issue. The new version is installed by 434 users. Most users are not heavy users, so I think these numbers are quite disturbing.

image

wbokkers avatar Dec 23 '21 08:12 wbokkers

Adding @ranjeshj.

MikeHillberg avatar Jan 03 '22 18:01 MikeHillberg

@MikeHillberg @ranjeshj I see this issue happening for all kind of scroll areas (e.g ScrollViewer). Not only ListViews and not only those that has ItemsUpdatingScrollMode set. For some sizes, scrolling to the end (using the touchpad) just crashes due to a layout cycle.

wbokkers avatar Jan 17 '22 15:01 wbokkers

You can see the crash happen for this simple XAML:

  <ScrollViewer
      Margin="12,8"
      Height="427.2">
      <StackPanel>
          <Border Margin="8" Height="192" Background="Green" Width="40"/>
          <Border Margin="8" Height="192"  Background="Blue" Width="40"/>
          <Border Margin="8" Background="Yellow" Height="30" Width="40"/>
      </StackPanel>
  </ScrollViewer>

Note the specified Height! The content of the scroll viewer is very simple. It looks like the crash is related to the content height AND the scroll viewer height.

wbokkers avatar Jan 17 '22 16:01 wbokkers

@wbokkers, thank you very much for the information you provided. This looks very much like a bug I have been investigating recently. That one depends on the Scale factor used on the machine, 100%, 125%, 150%, 175%, 200%, etc... It needed 175% to repro.

I tried all the Scale factors, but I could not repro the crash with the simple ScrollViewer markup above. What scale factor are you using on your machine to repro? Thank you.

RBrid avatar Jan 17 '22 19:01 RBrid

@RBrid My scale factor is 125% with a 1920x1080 resoltion. That is works with a different scale factor does not surprise me. The issue is very much dependent on the height of the scroll area and the contents, and changing the scale will change the sizes of the scroll area and the contents.

wbokkers avatar Jan 17 '22 19:01 wbokkers

The scale factor setting is probably why I don't see this issue occurring for all of our users.

wbokkers avatar Jan 17 '22 19:01 wbokkers

Changing the scale factor with only 1% will 'solve' the ScrollViewer-example on my machine. But I am not convinced that this will solve all situations.

wbokkers avatar Jan 17 '22 20:01 wbokkers

The XAML Controls Gallery app also crashes on some listviews when scrolling to the end of the list on my machine. This is probably the same issue: xamlcontrolsgallery://item/NavigationView

wbokkers avatar Jan 17 '22 20:01 wbokkers

Thank you @wbokkers, I can repro the crash now. The reason why I did not repro earlier is because I was using a plain UWP app. I needed to make use of WinUI 2.7 which changed the control template of the ScrollViewer by adding a 1px padding around its 2 ScrollBars.

RBrid avatar Jan 18 '22 18:01 RBrid

@RBrid Good to hear that you can repro the crash! It's a great relief to me that you are tackling this now. I found the crash on WinUI 3. If there's a fix on UWP, will this be ported to WinUI 3 as well?

wbokkers avatar Jan 18 '22 18:01 wbokkers

@wbokkers, yes you bet it will be ported into WinUI 3.

RBrid avatar Jan 18 '22 18:01 RBrid

@RBrid any change that a fix will be available in the next servicing release op app sdk 1.0? This crash is reported more frequently by users of our app: image

wbokkers avatar Jan 26 '22 13:01 wbokkers

While you are working on the fix, I decided to put the blame on Microsoft when this crash occurs. Users may think it is our app's fault. In the unhandled exception handler, I now will show the following message: image

wbokkers avatar Jan 26 '22 16:01 wbokkers

@gabbybilka will this issue be resolved in the next Windows App SDK servicing release? This is by far the most reported crash in our WinUI app.

wbokkers avatar Feb 09 '22 12:02 wbokkers

@gabbybilka @RBrid @marb2000

Why is this not fixed in the servicing release 1.0.1? All of our users with a scaling other than 100% will see frequent crashes. This bug even occurs in your own WinUI 3 gallery app.

This would be a blocking issue in every other professional software development organization! Why can Microsoft get away with this?

wbokkers avatar Mar 18 '22 13:03 wbokkers

@RBrid the issue is gone for most users since servicing-1.0.2, but it is still happening in some situations and for some users. 0.1% of our users still see this crash.

wbokkers avatar Apr 19 '22 08:04 wbokkers

@RBrid @wbokkers the issue is still exists in the latest UWP. We're using the List inside List, when we try to scroll the second list left and right frequently, the app is getting crashed by saying layout cycle detected crash.

AkshayFT avatar Apr 26 '22 06:04 AkshayFT

@RBrid Still regularly observed for Win App SDK 1.1.1, when large lists (~1000 items) are frequently scrolled up and down.

ynborokh avatar Jun 14 '22 21:06 ynborokh

I have same crash when I scroll ListView(109 items) crash_scroll image

Bondarenko1990 avatar Jun 15 '22 08:06 Bondarenko1990