Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] NullReference Exception: Grid.MeasureGrid (Android) #6247

Closed
InquisitorJax opened this issue May 21, 2019 · 21 comments · Fixed by #12646
Closed

[Bug] NullReference Exception: Grid.MeasureGrid (Android) #6247

InquisitorJax opened this issue May 21, 2019 · 21 comments · Fixed by #12646
Assignees
Labels
4.1.0 regression on 4.1.0 a/layout blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. e/4 🕓 4 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often in-progress This issue has an associated pull request that may resolve it! m/high impact ⬛ t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Milestone

Comments

@InquisitorJax
Copy link

InquisitorJax commented May 21, 2019

Description

the intention of this this code here

// Make copies so if InvalidateMeasure is called during layout we dont crash when these get nulled

Needs to be propagated through the rest of the grid control

The issue here
#6274
raised the probability of that type of situation arising.

The same treatment was already given to StackLayout but it should probably also be reconciled against the other layouts to see if there are similar scenarios where wayward invalidate measures can cause null exceptions

Related issue fixed for SL
#4689

Description Original

null reference exception when upgrading to xamarin forms 4 (android)

Steps to Reproduce

Expected Behavior

Don't crash

Actual Behavior

Crashes like a bomb :(

Basic Information

  • Version with issue: new release of version 4
  • Last known good version: last 3.x production version
  • IDE: VS 2017
  • Platform Target Frameworks:
    • iOS:
    • Android: 9
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

Stack Trace

UNHANDLED EXCEPTION:
05-21 22:38:23.984 I/MonoDroid( 6859): System.NullReferenceException: Object reference not set to an instance of an object.
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:146
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x00110] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:166
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:27
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
05-21 22:38:23.984 I/MonoDroid( 6859): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <95d915721ad748108ff096dce8f8f32c>:0
05-21 22:38:23.984 I/MonoDroid( 6859): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <95d915721ad748108ff096dce8f8f32c>:0
05-21 22:38:23.984 I/MonoDroid( 6859): at (wrapper dynamic-method) System.Object.40(intptr,intptr)
05-21 22:38:24.012 E/Crash Report( 6859): Time: 5/21/2019 10:38:23 PM
05-21 22:38:24.012 E/Crash Report( 6859): Error: Unhandled Exception
05-21 22:38:24.012 E/Crash Report( 6859): System.Exception: Android_UnhandledExceptionRaiser ---> System.NullReferenceException: Object reference not set to an instance of an object.
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:146
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x00110] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:166
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:27
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
[5:GlobalExceptionManagerBase.LogUnhandledException] 1|2019-05-21 22:38:24.0168|FATAL|Time: 5/21/2019 10:38:23 PM

@InquisitorJax InquisitorJax added s/unverified New report that has yet to be verified t/bug 🐛 labels May 21, 2019
@pauldipietro pauldipietro added this to New in Triage May 21, 2019
@samhouts
Copy link
Member

@InquisitorJax Can you please attach a small project that demonstrates this issue? Thanks!

@samhouts samhouts added p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels May 21, 2019
@samhouts samhouts moved this from New to Needs Info in Triage May 21, 2019
@InquisitorJax
Copy link
Author

InquisitorJax commented May 21, 2019

Hi @samhouts ... bit snowed under with work, can't make any promises. Perhaps try adding a Grid to NavigationPage.TitleView with some content. That's the only "out of the ordinary" thing I see there.
Edit: Nope - that's not it - just commented out and still happens.
Bit of a challenge to pinpoint with such a generic stack trace - I have grids everywhere - and it's not a small app :P

@InquisitorJax
Copy link
Author

I've found the offending grid - nested within a ContentView Grid... but's it's 1 a.m here - so I'm calling it a night. If whomever picks up this ticket needs to look at the code over skype - feel free to contact 'inquisitorjax'

@kwaclaw
Copy link

kwaclaw commented May 22, 2019

I get a similar error after upgrading to version 4. Seems that it happens when I hide the grid.
When the grid is initally hidden I get the error when I try top unhide it. In that case it happens in the NumberOfUnsetColumnWidth() method. Here the trace for hiding the grid.
(At the end of this message I am adding the XAML).

System.NullReferenceException: Object reference not set to an instance of an object.
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Grid.MeasuredStarredColumns (System.Double widthConstraint, System.Double heightConstraint) [0x00163] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:436
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:377
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0010e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:511
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x000a8] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:163
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:123
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0004e] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:58
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-22 09:52:40.573 I/MonoDroid(12283): at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
05-22 09:52:40.573 I/MonoDroid(12283): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <44fafc2e0f1847ee827456a85a04372d>:0
05-22 09:52:40.573 I/MonoDroid(12283): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <44fafc2e0f1847ee827456a85a04372d>:0

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="PalabraMobile.BrowserPage">
    <ContentPage.Resources>
        <Style TargetType="Button">
            <Setter Property="TextColor" Value="{Binding BarTextColor}" />
            <Setter Property="BackgroundColor" Value="Transparent" />
            <Setter Property="BorderColor" Value="Transparent" />
            <Setter Property="VerticalOptions" Value="Center" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Margin" Value="10,0,10,0" />
            <Setter Property="BorderWidth" Value="0" />
            <Setter Property="HeightRequest" Value="30" />
            <Setter Property="WidthRequest" Value="30" />
       </Style>
    </ContentPage.Resources>
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness">
            <On Platform="Default">0</On>
            <On Platform="iOS">0,21,0,0</On>
        </OnPlatform>
    </ContentPage.Padding>
    <ContentPage.Content>
        <StackLayout Orientation="Vertical" Margin="0" Padding="0" Spacing="0" HorizontalOptions="FillAndExpand">
            <Grid x:Name="toolBar" BackgroundColor="{Binding BarBackgroundColor}" Padding="0" Margin="0"
                  MinimumHeightRequest="50" HeightRequest="50" IsVisible="True">
                <StackLayout Orientation="Horizontal" FlowDirection="LeftToRight" Padding="0" Margin="0"
                             HorizontalOptions="Start" VerticalOptions="CenterAndExpand" >
                    <Button x:Name="backBtn" FontAttributes="Bold" Image="angle_left.png" Command="{Binding GoHome}" Margin="7,0,10,0" />
                    <Button x:Name="settingsBtn" Image="settings.png" Command="{Binding GoSettings}" />
                </StackLayout>
                <StackLayout Orientation="Horizontal" FlowDirection="RightToLeft" Padding="0" Margin="0"
                             HorizontalOptions="End" VerticalOptions="CenterAndExpand" >
                    <Button x:Name="hideBarBtn" Image="angle_up.png" Command="{Binding ShowBar}" Margin="10,0,7,0" />
                    <Button x:Name="refreshBtn" Image="reload.png" Command="{Binding Refresh}" />
                </StackLayout>
            </Grid>
            <Grid x:Name="browserView" BackgroundColor="White" Margin="0" Padding="0">
                <WebView x:Name="browser" WidthRequest="1000" HeightRequest="1000" Margin="0"
                         VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="Aqua"/>
                <ActivityIndicator x:Name="activityIndicator" Grid.Row="0" Grid.Column="0"
                         VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" IsRunning="False" />
                <Button x:Name="showBarBtn" Image="angle_down.png" Command="{Binding ShowBar}"
                        HorizontalOptions="End" VerticalOptions="Start" Margin="0,10,7,0" />
            </Grid>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

@InquisitorJax
Copy link
Author

@kwaclaw sounds about right. My landing page has a few grids / content views where the visibility is bound to ViewModel State.

@softsan
Copy link

softsan commented May 22, 2019

@kwaclaw Same problem here. @InquisitorJax did you find any resolution?

@InquisitorJax
Copy link
Author

@softsan not yet - unfortunately I have other priorities atm.

@RonnyBansemer
Copy link

RonnyBansemer commented May 23, 2019

I can confirm the problem as well. Seems to be a race condition after setting/updating the bindingcontext, because it does not occour every time.
Version: XF 4.0.0.346134-pre9

Exception

[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object.
[MonoDroid]   at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00195] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:113 
[MonoDroid]   at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485 
[MonoDroid]   at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60 
[MonoDroid]   at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762 
[MonoDroid]   at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644 
[MonoDroid]   at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 
[MonoDroid]   at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702 
[MonoDroid]   at Xamarin.Forms.TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0003c] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:41 
[MonoDroid]   at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762 
[MonoDroid]   at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644 
[MonoDroid]   at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 
[MonoDroid]   at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702 
[MonoDroid]   at Xamarin.Forms.Platform.Android.ItemContentView.OnMeasure (System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x0003b] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ItemContentView.cs:55 
[MonoDroid]   at Android.Views.View.n_OnMeasure_II (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x00009] in <44fafc2e0f1847ee827456a85a04372d>:0 
[MonoDroid]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.31(intptr,intptr,int,int)

Xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="...">
   <ContentView.Resources>
      <ResourceDictionary Source="/Theming/CustomerDisplay.xaml" />
      <Style TargetType="Label">
         <Setter Property="FontFamily"
                 Value="{StaticResource MonoFontThin}" />
         <Setter Property="TextColor"
                 Value="Black" />
         <Setter Property="FontSize"
                 Value="Large" />
      </Style>
   </ContentView.Resources>
   <Grid Margin="20,10,20,10"
         HorizontalOptions="FillAndExpand"
         VerticalOptions="FillAndExpand">
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="7*" />
         <ColumnDefinition Width="3*" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
         <RowDefinition Height="*" />
         <RowDefinition Height="60" />
      </Grid.RowDefinitions>
      <CollectionView ItemsSource="{Binding Path=Items}"
                      VerticalOptions="EndAndExpand"
                      HorizontalOptions="FillAndExpand"
                      SelectionMode="None"
                      Grid.ColumnSpan="2">
         <CollectionView.ItemTemplate> 
           <!-- many content... --> 
         </CollectionView.ItemTemplate>
      </CollectionView>
      <Label Text="Total"
             FontAttributes="Bold"
             VerticalOptions="CenterAndExpand"
             HorizontalOptions="FillAndExpand"
             Grid.Row="1" />
      <Label Text="{Binding Total}"
             FontAttributes="Bold"
             FontSize="42"
             VerticalOptions="CenterAndExpand"
             HorizontalOptions="EndAndExpand"
             Grid.Row="1"
             Grid.Column="1" />
   </Grid>
</ContentView>

Code behind

namespace My.Name.Space
{
   public partial class CustomerDisplayBookingView : ContentView
   {
      public CustomerDisplayBookingView(int width, int height, object bindingContext)
      {
         InitializeComponent();

         WidthRequest = width;
         HeightRequest = height;
         BindingContext = bindingContext;
      }
   }
}

Instanciation on looper thread

var view = new CustomerDisplayBookingView(854, 480, bookingLayout);

Further information
I also tested ListView and BindableLayout - same problem.

@Smoothstep
Copy link

I'm getting the same crash each time when navigating back from an oauth browser session.
When removing the grid, my AbsoluteLayout is misplacing it's children. This only happens with xamarin-auth backward navigation on android devices and could be connected to one or more plugins (Prism? Auth?).
Overall, the behavior is unexpected and this exception shouldn't be possible. People have already made reports about this issue back in 2017 and now it's occuring more frequently.

Special note
Since v4 with oauth, the GC is constantly logging informations about growing heaps (Nursery full). Not suprisingly, this incident appears right after the navigation, so there might be a leak somewhere.

@kwaclaw
Copy link

kwaclaw commented May 23, 2019

When I look at the number of bugs posted in the last 48 hours it seems wise to revert back to version 3.6.

@PureWeen
Copy link
Contributor

PureWeen commented May 24, 2019

Can anyone having this issue test with the nuget attached here?
#6260 (comment)

let me know if it still happens

Another fix that might work is to roll back to legacy renderers
Forms.SetFlags("UseLegacyRenderers");

@Saravanan-QWC
Copy link

Perfect, It works.

@jepl4052
Copy link

@PureWeen

Another fix that might work is to roll back to legacy renderers
Forms.SetFlags("UseLegacyRenderers");

I stumbled upon this same issue when upgrading to 4 from 3.6, and going back to legacy renderers according to your suggestion solved my crashes!

@RonnyBansemer
Copy link

In my case the problem was a not fully layouted forms view. There is a complex viewmodel with many bindings behind. Adding a delay solved my issue!

async static Task<ViewGroup> ConvertToNativeAsync(Xamarin.Forms.View view, Android.Content.Context context, bool ignoreDensity)
{
   var renderer = Platform.CreateRendererWithContext(view, context);

   if (renderer == null)
      return null;

   renderer.Tracker.UpdateLayout();

   var density = context.Resources.DisplayMetrics.Density;
   var nativeDensityModifier = ignoreDensity ? 1 : density;
   var formsDensityModifier = ignoreDensity ? density : 1;

   var nativeSize = new Xamarin.Forms.Rectangle(0, 0, view.WidthRequest * nativeDensityModifier, view.HeightRequest * nativeDensityModifier);
   var formsSize = new Xamarin.Forms.Rectangle(0, 0, view.WidthRequest / formsDensityModifier, view.HeightRequest / formsDensityModifier);

   var viewGroup = renderer.View as ViewGroup;
   viewGroup.LayoutParameters = new ViewGroup.LayoutParams((int)nativeSize.Width, (int)nativeSize.Height);

   view.Layout(formsSize);

   // Solves the problem!
   await Task.Delay(TimeSpan.FromMilliseconds(600));

   viewGroup.Layout(0, 0, (int)nativeSize.Width, (int)nativeSize.Height);

   return viewGroup;
}

@PureWeen PureWeen added this to the 4.1.0 milestone May 29, 2019
@PureWeen PureWeen added a/layout e/4 🕓 4 and removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified p/Android labels May 29, 2019
@PureWeen PureWeen moved this from Needs Info to Ready For Work in Triage May 29, 2019
@samhouts samhouts added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label May 29, 2019
@samhouts samhouts added the 4.1.0 regression on 4.1.0 label Sep 12, 2019
@samhouts samhouts removed this from the 4.1.0 milestone Sep 12, 2019
@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Nov 25, 2019
@overzealus
Copy link

I have this bug :(
Any fixes?
This bug seems to be random. Some users reports of single crashes, others - that crashes happens all times.

System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Grid.GetLastAutoColumn (Xamarin.Forms.BindableObject child) <0x102e82744 + 0x00048> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Grid.ExpandLastAutoColumnIfNeeded (System.Double width, System.Boolean expandToRequest) <0x102e80b38 + 0x000db> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) <0x102e81b38 + 0x002cf> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102e7f240 + 0x0007b> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) <0x102f0e4d0 + 0x00013> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102f0d868 + 0x000fb> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102e9d6fc + 0x00067> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) <0x102f0db64 + 0x000d3> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.ScrollView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102ecb9b0 + 0x000b3> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) <0x102f0e4d0 + 0x00013> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102f0d868 + 0x000fb> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x102e9d6fc + 0x00067> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) <0x102f0db64 + 0x000d3> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x102e9d878 + 0x00217> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x102e7ef48 + 0x00293> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x102e9de78 + 0x003d3> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x102e9de50 + 0x0000f> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Xamarin.Forms.Layout.ResolveLayoutChanges () <0x102e9eaac + 0x0013b> in <8e9ab226c9a54dbdb9366a1fb41e66e3#c93ba9f9493f3ea18adeba50535fd5ca>:0
at Foundation.NSAsyncActionDispatcher.Apply () <0x1037cd1bc + 0x00023> in <e7de71939f4649d9bdfb2e2411afa951#c93ba9f9493f3ea18adeba50535fd5ca>:0
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x103787a70 + 0x0003f> in <e7de71939f4649d9bdfb2e2411afa951#c93ba9f9493f3ea18adeba50535fd5ca>:0
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x1037879c8 + 0x00053> in <e7de71939f4649d9bdfb2e2411afa951#c93ba9f9493f3ea18adeba50535fd5ca>:0
at MyAppXamarinForms.iOS.Application.Main (System.String[] args) <0x1029164d8 + 0x00267> in <48dc354de05d4385bfcd50bcd44892a5#c93ba9f9493f3ea18adeba50535fd5ca>:0

@thisisthekap
Copy link
Contributor

thisisthekap commented Feb 3, 2020

We also got an AppCenter crash report with this issue for iPhone 6s (iOS 13.3). This issue is imho not related to a specific platform, but rather to Xamarin.Forms in general.

@samhouts samhouts removed the inactive Issue is older than 6 months and needs to be retested label Feb 6, 2020
@thisisthekap
Copy link
Contributor

I now got the confirmation that this bug is definitely a cross platform issue, as it also happened on an iPhone XR running iOS 13.3.1.

The stacktrace: https://pastebin.com/hfaHXN2x

@Huaba93
Copy link

Huaba93 commented Feb 25, 2020

Same exception here. It only occurs on a page where the visibility of a grid is bound to a viewmodel property. I can not reproduce it, I only see a lot of appcenter traces for iPhones. Have not seen this on Android.

Xamarin Exception Stack: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Grid.MeasuredStarredColumns (System.Double widthConstraint, System.Double heightConstraint) <0x102323e48 + 0x00330> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) <0x102323908 + 0x0004f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) <0x1023242d4 + 0x00287> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x1023219dc + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) <0x1023a62b4 + 0x00013> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x1023a564c + 0x000fb> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x10233a5fc + 0x00067> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) <0x1023a5948 + 0x000d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.FlexLayout+<>c__DisplayClass61_0.<AddChild>b__0 (Xamarin.Flex.Item it, System.Single& w, System.Single& h) <0x10231a6a4 + 0x0014b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Flex.Item.layout_item (Xamarin.Flex.Item item, System.Single width, System.Single height) <0x1022db730 + 0x0041f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Flex.Item.Layout () <0x1022db548 + 0x00053> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.FlexLayout.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) <0x1023190f8 + 0x00cf7> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x1023a564c + 0x000fb> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x10233a5fc + 0x00067> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) <0x1023a5948 + 0x000d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) <0x10238c428 + 0x003f3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) <0x10238c260 + 0x0011b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x10238bfb8 + 0x00057> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) <0x1023a62b4 + 0x00013> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x1023a564c + 0x000fb> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) <0x10233a5fc + 0x00067> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) <0x1023a5948 + 0x000d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.ScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x102366ca8 + 0x002b3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x10239858c + 0x000db> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x1023216e4 + 0x00293> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.ContentPresenter.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x102304c50 + 0x000d7> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x1023216e4 + 0x00293> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x10239858c + 0x000db> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.UpdateChildrenLayout () <0x10233ad78 + 0x003d3> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) <0x10233ad50 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x1023553c4 + 0x001bf> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.UpdateChildrenLayout () <0x102355b20 + 0x0037f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.OnSizeAllocated (System.Double width, System.Double height) <0x102355b08 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Sepp.Mobile.Views.Base.PrismPageBase.OnSizeAllocated (System.Double width, System.Double height) <0x1015b3f94 + 0x000eb> in <d14bb11b8ea043119a88017e4d532530#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) <0x1023a7b60 + 0x0007b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) <0x1023a322c + 0x0009b> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) <0x10233a778 + 0x002ef> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) <0x1023553c4 + 0x001bf> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.UpdateChildrenLayout () <0x102355b20 + 0x0037f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.OnSizeAllocated (System.Double width, System.Double height) <0x102355b08 + 0x0000f> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Page.set_ContainerArea (Xamarin.Forms.Rectangle value) <0x1023546b8 + 0x00087> in <3176ecd5cae2414a857d4580e79dcda0#f3ca2cf5ea24d885c43fd37312493362>:0 at Xamarin.Forms.Platform.iOS.NavigationRenderer.ViewDidLayoutSubviews () <0x1024f80dc + 0x002db> in <52b46d19096449e8b2ba6f0a6feffc05#f3ca2cf5ea24d885c43fd37312493362>:0 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x102056e9c + 0x0003f> in <79170d3ca0a34f20a27c5ea33d79161f#f3ca2cf5ea24d885c43fd37312493362>:0 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x102056df4 + 0x00053> in <79170d3ca0a34f20a27c5ea33d79161f#f3ca2cf5ea24d885c43fd37312493362>:0 at Sepp.Mobile.iOS.Application.Main (System.String[] args) <0x10100e5e8 + 0x00033> in <43ea4d0585a046bfb1a11389be8b7aed#f3ca2cf5ea24d885c43fd37312493362>:0

@stepkillah
Copy link

stepkillah commented Jun 24, 2020

Any updates on this one?

Update:
Checked the Grid source code a bit, and see that _columns and _rows has been set to null in InvalidateMeasureInternal, and in code itself - there is no protection against it. So wondering what is the reason for setting it to null in here, because if remove these lines - it shouldn't crash anymore for cases like IsVisible. At least code Issue6247_Grid doesn't crash anymore (but as far as it's some sort threading issue it still might occur in scenarios where _rows or _columns changes but with different exception).

		internal override void InvalidateMeasureInternal(InvalidationTrigger trigger)
		{
			base.InvalidateMeasureInternal(trigger);
			_columns = null;
			_rows = null;
		}

It can be reproduced with this code if you have few rows/columns defined

class Issue6247_Grid : Grid
		{
			protected override void LayoutChildren(double x, double y, double width, double height)
			{
				Task.Run(async () =>
				{
					await Task.Delay(1);
					InvalidateMeasureInternal(InvalidationTrigger.Undefined);
				});

				base.LayoutChildren(x, y, width, height);
			}
		}

@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts added this to To do in vNext+1 (5.0.0) Aug 14, 2020
@jakub-sobczuk
Copy link

Hi

Any updates on this issue?
We have application that have number of grids using autocells, and development is on very advanced stage. This issue occurs from time to time and is quite a problem considering app size :-)
Any info about planned fix date/progress will be valuable, as we need to plan a strategy to solve this issue.

Thank you!

@hartez hartez self-assigned this Oct 28, 2020
@hartez hartez moved this from To do-High impact to In progress in Other Ready For Work Oct 28, 2020
@hartez hartez moved this from To do to In Progress in vNext+1 (5.0.0) Oct 28, 2020
@hartez hartez added the in-progress This issue has an associated pull request that may resolve it! label Oct 28, 2020
@PureWeen PureWeen added the blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. label Nov 2, 2020
Other Ready For Work automation moved this from In progress to Done Nov 11, 2020
vNext+1 (5.0.0) automation moved this from In Progress to Done Nov 11, 2020
rmarinho pushed a commit that referenced this issue Nov 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4.1.0 regression on 4.1.0 a/layout blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. e/4 🕓 4 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often in-progress This issue has an associated pull request that may resolve it! m/high impact ⬛ t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
Development

Successfully merging a pull request may close this issue.