Bug 59130 - Removing and re-adding a view with a TapGestureRecognizer results in a NullReferenceException
Summary: Removing and re-adding a view with a TapGestureRecognizer results in a NullRe...
Status: RESOLVED DUPLICATE of bug 59097
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.4.0
Hardware: PC Windows
: High critical
Target Milestone: 2.4.0
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-08-30 23:57 UTC by Pete Schmitz
Modified: 2017-09-03 23:54 UTC (History)
5 users (show)

Tags: ac android tapgesturerecognizer nre stacklayout
Is this bug a regression?: ---
Last known good build:


Attachments
reproduction project (134.92 KB, application/x-zip-compressed)
2017-08-30 23:57 UTC, Pete Schmitz
Details
repro project (236.25 KB, application/x-zip-compressed)
2017-08-31 17:02 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 59097

Description Pete Schmitz 2017-08-30 23:57:10 UTC
Created attachment 24489 [details]
reproduction project

Issue: After updating to 2.4.0.269-pre2 our Android app encounters an NRE propagating from a gesture event:

Reproduction:

- Populate a stacklayout with views that contain a tapgesture

- Clear that stacklayout's children

- Re-add the views

From attached repro project

- Tap one of the "Tabs"

- The tab is activated, children are re-added (App.cs:LN151), and the app encounters the exception

We can workaround this issue, and the current logic may appear redundant - but it works perfectly fine on iOS and previous versions of forms. Additionally, there are other areas in our app where this behavior makes more sense and would require us to refactor in 2.4-0's current state.


Stack:

08-30 16:21:51.459 I/MonoDroid( 6014): System.NullReferenceException: Object reference not set to an instance of an object.
08-30 16:21:51.459 I/MonoDroid( 6014):   at Xamarin.Forms.Platform.Android.InnerGestureListener.HasDoubleTapHandler () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\FormsTextView.cs:31 
08-30 16:21:51.459 I/MonoDroid( 6014):   at Xamarin.Forms.Platform.Android.InnerGestureListener.Android.Views.GestureDetector.IOnDoubleTapListener.OnSingleTapConfirmed (Android.Views.MotionEvent e) <0x90926260 + 0x00043> in <71a3106472a0430fb37743bb13e044f9>:0 
08-30 16:21:51.459 I/MonoDroid( 6014):   at Android.Views.GestureDetector+IOnDoubleTapListenerInvoker.n_OnSingleTapConfirmed_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in <9ab9faae1b4b4f0da28e7c4ac61e2c78>:0 
08-30 16:21:51.459 I/MonoDroid( 6014):   at (wrapper dynamic-method) System.Object:441753d4-c705-410a-96d1-7e9d0a8e4a0e (intptr,intptr,intptr)
Comment 1 Mark Radcliffe 2017-08-31 05:38:57 UTC
I am also having an issue like this, in one of my views, I don't even have tap guestures at all in view and I still get this same thing occur.


08-31 17:09:08.319 I/MonoDroid(14538): System.NullReferenceException: Object reference not set to an instance of an object.
08-31 17:09:08.319 I/MonoDroid(14538):   at Xamarin.Forms.Platform.Android.InnerGestureListener.HasDoubleTapHandler () <0xcddfaa50 + 0x00054> in <71a3106472a0430fb37743bb13e044f9>:0 
08-31 17:09:08.319 I/MonoDroid(14538):   at Xamarin.Forms.Platform.Android.InnerGestureListener.Android.Views.GestureDetector.IOnDoubleTapListener.OnSingleTapConfirmed (Android.Views.MotionEvent e) <0xc9c460c0 + 0x00063> in <71a3106472a0430fb37743bb13e044f9>:0 
08-31 17:09:08.319 I/MonoDroid(14538):   at Android.Views.GestureDetector+IOnDoubleTapListenerInvoker.n_OnSingleTapConfirmed_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in <6d4595838c33467bba47fea9354bd9ac>:0 
08-31 17:09:08.319 I/MonoDroid(14538):   at (wrapper dynamic-method) System.Object:e905fa32-587f-481f-beb6-f7e530fbec6f (intptr,intptr,intptr)

It occurs when a tap of the screen is done while the view is adding or removing views from a layout view like grids/stacklayouts. mashing while navigating to a new view is the easiest way to make it occur. I have no work around for this other than blocking clicks during the load using a contentpage renderer and overriding DispatchTouchEvent and just returning if the view is too new. But this doesn't fix the cases where the page loads the view dynamically or is complex and takes a bit of extra time :(.

How did you work around your issue?
Comment 2 Jimmy [MSFT] 2017-08-31 17:02:38 UTC
Created attachment 24506 [details]
repro project

Thank you for filing this report! I ran the repro project on Android and I could reproduce the issue. I've attached a further minimized project based on the on original one.  


### Platforms Affected
Android


### Steps to reproduce
1. Run the project on Android
2. Tap the "Press Here" Label


### Expected Results
The app will not crash and the debug output will indicate that the Label was tapped.


### Actual Results
The app crashes with an NRE:

> System.NullReferenceException: Object reference not set to an instance of an object.
>   at Xamarin.Forms.Platform.Android.InnerGestureListener.HasDoubleTapHandler () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\FormsTextView.cs:31 
>   at Xamarin.Forms.Platform.Android.InnerGestureListener.Android.Views.GestureDetector.IOnDoubleTapListener.OnSingleTapConfirmed (Android.Views.MotionEvent e) <0x9a751500 + 0x00063> in <71a3106472a0430fb37743bb13e044f9>:0 
>   at Android.Views.GestureDetector+IOnDoubleTapListenerInvoker.n_OnSingleTapConfirmed_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in <d278c06ad5684d6882c743a94a93ebc2>:0 
>   at (wrapper dynamic-method) System.Object:84d6eaea-25e0-48cc-a4db-2cea554eb68b (intptr,intptr,intptr)


### Version Test
2.4.0-pre2  BAD
2.3.4.270   GOOD
Comment 3 philip 2017-08-31 22:43:04 UTC
I see the same issue, except it happens when removing an element from the UI hierarchy from within one of the callbacks (e.g. button click) for that element.
Comment 4 Jimmy [MSFT] 2017-09-03 23:54:38 UTC

*** This bug has been marked as a duplicate of bug 59097 ***