Bug 59716 - NRE on ListView's cell update when templated with grid and label
Summary: NRE on ListView's cell update when templated with grid and label
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-25 08:21 UTC by mailcannon
Modified: 2017-10-03 09:51 UTC (History)
2 users (show)

See Also:
Tags: hasunevenrows, listview, ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (186.09 KB, application/x-7z-compressed)
2017-09-25 08:21 UTC, mailcannon
Details

Description mailcannon 2017-09-25 08:21:37 UTC
Created attachment 24908 [details]
repro project

I have this xaml. And items adding by an event(i.e. asynchronously).

    <StackLayout>
        <Button Text="Update" Command="{Binding UpdateListCommand}" />
        <ListView ItemsSource="{Binding Items}"
                  HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Label
                                BackgroundColor="Transparent"
                                Text="{Binding }"
                                VerticalOptions="Center"
                                HorizontalOptions="Center"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

When HasUnevenRows="True", application crashes exactly on third click on "Update" button with NullReferenceException in LabelRenderer. 
When i set HasUnevenRows="False" or remove the Grid or make list updating synchronous - everything working fine.
Repro project included
Comment 1 Paul DiPietro [MSFT] 2017-09-25 19:33:11 UTC
Verified testing the behavior against 2.4.0-pre3.
Comment 2 mailcannon 2017-10-02 11:30:25 UTC
still crashes with 2.4.0.282
Comment 3 mailcannon 2017-10-03 09:37:25 UTC
the workarround i found is:

to set CachingStrategy="RecycleElement" ||
to set HasUnevenRows="False" ||
to remove the Grid from viewcell template
Comment 4 mailcannon 2017-10-03 09:41:35 UTC
I changed all ListView's behaviours to CachingStrategy="RecycleElement", bun unfortunatelly, app is still crashes rarely with labels that are not in ViewCell template.

Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateText()
Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
<Module>.invoke_void_object_PropertyChangedEventArgs(object, PropertyChangedEventArgs)(wrapper delegate-invoke)
Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName)
Xamarin.Forms.Element.OnPropertyChanged(string propertyName)
Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent)
Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, BindableObject.SetValuePrivateFlags privateAttributes)
Xamarin.Forms.BindingExpression.ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget)
Xamarin.Forms.BindingExpression.Apply(bool fromTarget)
Xamarin.Forms.BindingExpression.BindingExpressionPart.<PropertyChanged>b__47_0()
Foundation.NSAsyncActionDispatcher.Apply()
UIKit.UIApplication.UIApplicationMain(int, string[], intptr, intptr)(wrapper managed-to-native)
UIKit.UIApplication.Main(string[] args, IntPtr principal, IntPtr delegate)
UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName)
TimeTracker.iOS.Application.Main(string[] args)

as you can see, crashes after OnElementPropertyChanged call as well aw when label is in ViewCell template.
Comment 5 mailcannon 2017-10-03 09:44:58 UTC
Also, i found out that if i remove any labels from my own application, its still crashes with ObjectDisposedException on images that are left in ViewCell template.
Comment 6 mailcannon 2017-10-03 09:50:52 UTC
In repro project, if change
 
<Label
  BackgroundColor="Transparent"
  Text="{Binding }"
  VerticalOptions="Center"
  HorizontalOptions="Center"/>

with 

<Image
  Source="Icon-76"
  BackgroundColor="Transparent"
  VerticalOptions="Center"
  HorizontalOptions="Center"/>

then app is crashing after few updates with 

NSInternalInconsistencyException Reason: table view row height must not be negative - provided height for index path (<UIMutableIndexPath 0x7fa282b88110> 2 indexes [0, 0]) is -1.000000

no matter what CachingStrategy is set.
Comment 7 mailcannon 2017-10-03 09:51:24 UTC
please, do something, this is not stable at all

Note You need to log in before you can comment on or make changes to this bug.