Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
InquisitorJax opened this issue May 21, 2019 · 15 comments
Open

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

InquisitorJax opened this issue May 21, 2019 · 15 comments

Comments

@InquisitorJax
Copy link

@InquisitorJax 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

@samhouts

This comment has been minimized.

Copy link
Member

@samhouts samhouts commented May 21, 2019

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

@samhouts samhouts moved this from New to Needs Info in Triage May 21, 2019
@InquisitorJax

This comment has been minimized.

Copy link
Author

@InquisitorJax 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

This comment has been minimized.

Copy link
Author

@InquisitorJax InquisitorJax commented May 21, 2019

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

This comment has been minimized.

Copy link

@kwaclaw 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

This comment has been minimized.

Copy link
Author

@InquisitorJax InquisitorJax commented May 22, 2019

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

@softsan

This comment has been minimized.

Copy link

@softsan softsan commented May 22, 2019

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

@InquisitorJax

This comment has been minimized.

Copy link
Author

@InquisitorJax InquisitorJax commented May 22, 2019

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

@RonnyBansemer

This comment has been minimized.

Copy link

@RonnyBansemer 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.

@SpeedPing

This comment has been minimized.

Copy link

@SpeedPing SpeedPing commented May 23, 2019

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

This comment has been minimized.

Copy link

@kwaclaw 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

This comment has been minimized.

Copy link
Contributor

@PureWeen 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

This comment has been minimized.

Copy link

@Saravanan-QWC Saravanan-QWC commented May 27, 2019

Perfect, It works.

@jepl4052

This comment has been minimized.

Copy link

@jepl4052 jepl4052 commented May 28, 2019

@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

This comment has been minimized.

Copy link

@RonnyBansemer RonnyBansemer commented May 28, 2019

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;
}
@samhouts samhouts added this to To do in v4.1.0 May 29, 2019
@samhouts samhouts added this to To do in Other Ready For Work May 29, 2019
@samhouts samhouts removed this from Ready For Work in Triage May 29, 2019
@InquisitorJax

This comment has been minimized.

Copy link
Author

@InquisitorJax InquisitorJax commented May 29, 2019

Using the Legacy Renderers work-around - my app launches without crashing - but unfortunately something is running in the background that freezes the app:

Looks like some sort of memory leak: (Works just fine when rolling back to 3.X Forms)

R_BRIDGE bridges 859 objects 859 opaque 0 colors 859 colors-bridged 859 colors-visible 859 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.06ms tarjan 0.12ms scc-setup 0.11ms gather-xref 0.02ms xref-setup 0.01ms cleanup 0.05ms
05-30 00:48:40.932 D/Mono ( 8997): GC_BRIDGE: Complete, was running for 10.34ms
05-30 00:48:40.932 D/Mono ( 8997): GC_MINOR: (Nursery full) time 2.39ms, stw 3.68ms promoted 94K major size: 3664K in use: 2874K los size: 2048K in use: 1411K
05-30 00:48:41.201 D/Mono ( 8997): DllImport searching in: '__Internal' ('(null)').
05-30 00:48:41.201 D/Mono ( 8997): Searching for 'java_interop_jnienv_call_float_method_a'.
05-30 00:48:41.201 D/Mono ( 8997): Probing 'java_interop_jnienv_call_float_method_a'.
05-30 00:48:41.201 D/Mono ( 8997): Found as 'java_interop_jnienv_call_float_method_a'.
05-30 00:48:41.213 I/Choreographer( 8997): Skipped 228 frames! The application may be doing too much work on its main thread.
05-30 00:48:41.291 I/OpenGLRenderer( 8997): Davey! duration=3883ms; Flags=0, IntendedVsync=141482019177109, Vsync=141485819176957, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=141485825662740, AnimationStart=141485825709320, PerformTraversalsStart=141485826095070, DrawStart=141485832601980, SyncQueued=141485835440340, SyncStart=141485835499050, IssueDrawCommandsStart=141485836426240, SwapBuffers=141485879979900, FrameCompleted=141485903055300, DequeueBufferDuration=838000, QueueBufferDuration=848000,
05-30 00:48:41.514 I/cilabs.remotim( 8997): Explicit concurrent copying GC freed 9146(491KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 2MB/4MB, paused 453us total 9.765ms
05-30 00:48:41.516 D/Mono ( 8997): GC_TAR_BRIDGE bridges 858 objects 858 opaque 0 colors 858 colors-bridged 858 colors-visible 858 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.04ms tarjan 0.11ms scc-setup 0.09ms gather-xref 0.02ms xref-setup 0.01ms cleanup 0.28ms
05-30 00:48:41.516 D/Mono ( 8997): GC_BRIDGE: Complete, was running for 13.20ms
05-30 00:48:41.516 D/Mono ( 8997): GC_MINOR: (Nursery full) time 3.17ms, stw 3.93ms promoted 100K major size: 3776K in use: 2977K los size: 2048K in use: 1858K
05-30 00:48:42.074 I/cilabs.remotim( 8997): Explicit concurrent copying GC freed 9155(464KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 2MB/4MB, paused 425us total 8.584ms
05-30 00:48:42.075 D/Mono ( 8997): GC_TAR_BRIDGE bridges 858 objects 858 opaque 0 colors 858 colors-bridged 858 colors-visible 858 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.04ms tarjan 0.11ms scc-setup 0.10ms gather-xref 0.02ms xref-setup 0.01ms cleanup 0.06ms
05-30 00:48:42.075 D/Mono ( 8997): GC_BRIDGE: Complete, was running for 10.80ms

@samhouts samhouts added the i/high label May 29, 2019
@samhouts samhouts added the 4.1.0 label Sep 12, 2019
@samhouts samhouts removed this from the 4.1.0 milestone Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v4.1.0
  
To do
9 participants
You can’t perform that action at this time.