Bug 59919 - Multiple rapid taps on the picker crashes the app (Android)
Summary: Multiple rapid taps on the picker crashes the app (Android)
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-03 14:07 UTC by Mihail Duchev
Modified: 2017-11-15 18:59 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
The output for when the bug occurs (4.40 KB, text/plain)
2017-10-03 14:07 UTC, Mihail Duchev
Details

Description Mihail Duchev 2017-10-03 14:07:07 UTC
Created attachment 25073 [details]
The output for when the bug occurs

I have found an issue where if you have a picker within an Android app, that has AppCompat enabled and has custom renderer inheriting from Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer, when you tap the picker very rapidly multiple times and after each tap you tap outside the picker (in order to close it), the app crashes after several clicks to open-close the picker. 
The steps are very fast, but are as follows: click on the picker in order to open it, after that very fast click outside the picker. Repeat multiple times.

This is a possible duplicate/regression of #41717.

I have attached the output, which tells me that there is a null reference exception causing the app to crashes. The cause of this is in line 115 from PickerRenderer for AppCompat. 
Here is the line: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs#L115

I guess that at some point before closing/opening the next picker, the dialog becomes null, even after all of the checks.

When we look at the git blame, we can see this:
https://github.com/xamarin/Xamarin.Forms/commit/9c36f133ad1017b7126330768a8b6c986a051a95
This was the fix for 41717 that was released with 2.4.

Unfortunately, I can't confirm that this was an issue before the 2.4 release. 


A sample of my picker renderer:

using Android.Util;
using MyProject.CustomRenderers;
using MyProject.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using PickerRenderer = Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer;

[assembly: ExportRenderer(typeof(MyPicker), typeof(MyPickerRenderer))]
namespace MyProject.Droid.Renderers
{
    public class MyPickerRenderer : PickerRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null && Element is MyPicker pickerElement)
            {
                // Change fontSize and placeholderFontSize
                if (pickerElement.FontSize.HasValue)
                {
                    Control.SetTextSize(ComplexUnitType.Sp, (float)pickerElement.FontSize.Value);
                }
            }
        }
    }
}
Comment 1 Paul DiPietro [MSFT] 2017-10-03 16:52:57 UTC
What sort of device are you testing this on (for speed, I assume you're using a device) and do you have a more complete project to upload for debugging? I cannot seem to reproduce this despite rather quickly tapping in and out of the Picker on an S8 device.
Comment 2 Mihail Duchev 2017-10-04 09:32:40 UTC
Sorry for missing this - this happened on my HTC 10 running Android 7.0 and also on Samsung Galaxy S6 Edge running 7.0.
Unfortunately, I cannot upload a sample project, but I will try my best to describe the workflow that we have:

1) We are opening a certain page;
2) In the ctor we create an instance of our binded viewModel;
3) In the viewModel's ctor we start loading the data to the picker. The data is being loaded asynchronously via GET request. The request is not being awaited;
4) The picker is being binded to an ObservableCollection of other viewModels. When we get the result from our request, we simply set the result to the collection.

That's it.

NOTE: Opening the picker doesn't initiate another GET request.
Comment 3 Paul DiPietro [MSFT] 2017-11-15 18:59:14 UTC
To the reporter or anyone else experiencing the issue, reopen this when we can get a reproduction project to help us investigate further. Thanks.

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