MPowerKit / VirtualizeListView

.NET MAUI ListView renderers. Improves performance for MAUI ListView, adds additional behaviors
MIT License
69 stars 10 forks source link

LinearItemsLayoutManager Arrange can throw IndexOutOfBounds #6

Closed daltzctr closed 1 month ago

daltzctr commented 1 month ago

I reproduced this by having a complex List of data that I'm dynamically replacing the binding of. So setting ItemsSource multiple times in code behind.

I've traced this down to https://github.com/MPowerKit/VirtualizeListView/blob/995e8975264fa99ff93d17cfc4f239f3c8a8173a/MPowerKit.VirtualizeListView/LinearItemsLayoutManager.cs#L51

with a patch that works for me going from

var prevItemBounds = prevIndex == -1 ? new() : items[prevIndex].Bounds;

to

var prevItemBounds = prevIndex == -1 || prevIndex >= items.Count ? new() : items[prevIndex].Bounds;
Alex-Dobrynin commented 1 month ago

But i just thought, that this is not the fix. fix is to add this condition to if statement in the beginning of this method, so you immediately return from the method

Alex-Dobrynin commented 1 month ago

Also, can you provide me repro? I just wondering when this happens

Alex-Dobrynin commented 1 month ago

fixed in 1.1.6

MichaelFrenkel commented 1 month ago

@Alex-Dobrynin I've reproduced the crash on 1.1.6

MichaelFrenkel commented 1 month ago

also, in AppCenter crashlytics I see the similar issue. lib version is 1.1.1, iOS

ArgumentOutOfRange_IndexMustBeLess Arg_ParamName_Name, index

MPowerKit.VirtualizeListView.GroupableDataAdapter.OnCreateCell(DataTemplate template, Int32 position)
MPowerKit.VirtualizeListView.ItemsLayoutManager.InvalidateLayout()
MPowerKit.VirtualizeListView.ItemsLayoutManager.Control_SizeChanged(Object sender, EventArgs e)
Microsoft.Maui.Controls.VisualElement.UpdateBoundsComponents(Rect bounds)
Microsoft.Maui.Controls.VisualElement.set_Frame(Rect value)
Microsoft.Maui.Controls.ScrollView.ArrangeOverride(Rect bounds)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange(Rect bounds)
Microsoft.Maui.Controls.Compatibility.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rect region)
Microsoft.Maui.Controls.TemplatedView.LayoutChildren(Double x, Double y, Double width, Double height)
Microsoft.Maui.Controls.Compatibility.Layout.UpdateChildrenLayout()
Microsoft.Maui.Controls.Compatibility.Layout.OnSizeAllocated(Double width, Double height)
Microsoft.Maui.Controls.VisualElement.UpdateBoundsComponents(Rect bounds)
Microsoft.Maui.Controls.VisualElement.set_Frame(Rect value)
Microsoft.Maui.Controls.TemplatedView.ArrangeOverride(Rect bounds)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange(Rect bounds)
Microsoft.Maui.Controls.Compatibility.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rect region)
Microsoft.Maui.Controls.TemplatedView.LayoutChildren(Double x, Double y, Double width, Double height)
Microsoft.Maui.Controls.Compatibility.Layout.UpdateChildrenLayout()
Microsoft.Maui.Controls.Compatibility.Layout.OnSizeAllocated(Double width, Double height)
Microsoft.Maui.Controls.VisualElement.UpdateBoundsComponents(Rect bounds)
Microsoft.Maui.Controls.VisualElement.set_Frame(Rect value)
Microsoft.Maui.Controls.TemplatedView.ArrangeOverride(Rect bounds)
Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange(Rect bounds)
Microsoft.Maui.Layouts.GridLayoutManager.ArrangeChildren(Rect bounds)
Microsoft.Maui.Controls.Layout.CrossPlatformArrange(Rect bounds)
Microsoft.Maui.Platform.MauiView.CrossPlatformArrange(Rect bounds)
Microsoft.Maui.Platform.MauiView.LayoutSubviews()
ObjCRuntime.Runtime.ThrowException(IntPtr )
UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
UIKit.UIApplication.Main(String[] , Type , Type )
Alex-Dobrynin commented 1 month ago

this is different issue than previous one.

Should i use the same xaml to reproduce?

MichaelFrenkel commented 1 month ago

honestly don't know, I see the crash in MPowerKit.VirtualizeListView.GroupableDataAdapter.OnCreateCell(DataTemplate template, Int32 position) for the first time.

But the original issue #6 crash is still reproducible and I believe you can use the repro I've provided

Alex-Dobrynin commented 1 month ago

@MichaelFrenkel I just pushed branch fix_#6, check it please locally before i make a nuget update

Alex-Dobrynin commented 1 month ago

also, in AppCenter crashlytics I see the similar issue. lib version is 1.1.1, iOS

As I understand it was only in that 1.1.1 version only? if yes, then I suppose it was already fixed some time ago

MichaelFrenkel commented 1 month ago

also, in AppCenter crashlytics I see the similar issue. lib version is 1.1.1, iOS

As I understand it was only in that 1.1.1 version only? if yes, then I suppose it was already fixed some time ago

probably yes. If we have this crash after upgrading the library, will create a new issue

Alex-Dobrynin commented 1 month ago

@MichaelFrenkel Did you have possibility to check that branch? I`ve already fixed another bug and want to release it

MichaelFrenkel commented 1 month ago

@Alex-Dobrynin yeap, I haven't reproduced it but I also asked our automation team to check the fix, will provide details later

Alex-Dobrynin commented 1 month ago

@MichaelFrenkel any news from automation team?

MichaelFrenkel commented 1 month ago

@MichaelFrenkel any news from automation team?

yeap, the crash hasn't been reproduced

Alex-Dobrynin commented 1 month ago

thanks