Xamarin.forms: FlexLayout - NullReferenceException when navigating to a page

Created on 6 Jul 2018  路  7Comments  路  Source: xamarin/Xamarin.Forms

Description

A NullReferenceException is thrown when navigating back/to a page while having a FlexLayout with dynamically changing items in the source page. This happens on the Flex.Item _root when its last layout cycle is triggered.

Steps to Reproduce

  1. Create a FlexLayout with dynamically changing items such as by modifying visibility or sizes periodically.
  2. Navigate to another page

Expected Behavior

App should not crash

Actual Behavior

A NullReferenceException is thrown that causes the app to crash

Basic Information

  • Version with issue: Latest (reproduced in the CoreGallery sample)
  • Platform Target Frameworks:

    • iOS: 11.4

    • Android: 8.0

    • UWP: Cannot try at this moment

Reproduction Link

francedot/nullref-flexlayout-sample

Stack trace

Xamarin.Forms.FlexLayout.Layout(double x, double y, double width, double height) in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/FlexLayout.cs:444
Xamarin.Forms.FlexLayout.LayoutChildren(double x, double y, double width, double height) in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/FlexLayout.cs:391
Xamarin.Forms.Layout.UpdateChildrenLayout() in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/Layout.cs:263
Xamarin.Forms.Layout.OnSizeAllocated(double width, double height) in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/Layout.cs:223
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height) in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/VisualElement.cs:692
Xamarin.Forms.Layout.<>c.<OnChildMeasureInvalidated>b__45_0() in /Users/francesco/Xamarin.Forms/Xamarin.Forms.Core/Layout.cs:380
flex layout 4 bug

All 7 comments

It may be related to issue #3183

@StephaneDelcroix Simply a missing null check? Francedot's got a proposed fix. There are other such null checks in the code indicating it's not unexpected to get callbacks when _root is null...

@hartez I don't get the reference to XamlC. is there something I'm missing ?

@StephaneDelcroix My bad - I got confused between #3183 and #3226.

@samhouts we are facing a random crash on FlexLayout , This happens randomly when the page refreshes after the token expires. we are not able reproduce it continuously, Any suggestions on the reason would be a great help.
FlexLayout.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
System.NullReferenceException: Object reference not set to an instance of an object

FlexLayout.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
ScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height)
Layout.UpdateChildrenLayout ()
Layout.OnSizeAllocated (System.Double width, System.Double height)
VisualElement.SizeAllocated (System.Double width, System.Double height)
Layout.ResolveLayoutChanges ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)

@Srikanth540-L Same here. Exact same issue.

@uksreejith Please refer this GitHub bug link https://github.com/xamarin/Xamarin.Forms/issues/9340#event-3111075308

Was this page helpful?
0 / 5 - 0 ratings