Bug 23940 - CADisplayLinkTicker with ActivityIndicator accesses UI off main thread and crashes
Summary: CADisplayLinkTicker with ActivityIndicator accesses UI off main thread and cr...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-10-20 14:20 UTC by luca.barbieri
Modified: 2016-09-25 15:13 UTC (History)
6 users (show)

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

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 NOT_REPRODUCIBLE

Description luca.barbieri 2014-10-20 14:20:47 UTC
It appears that CADisplayLinkTicker is accessing the UI on a non-main thread, as you can see by this stack trace.

Also, it is crashing.

This is happening after I pressed a button that resulted in setting a "ActionRequested" property that, through data binding, caused the button to because invisible (IsVisible=false) and an ActivityIndicator to become visible (IsVisible=true).

And in fact, the view variable on the VisualElementTracker.OnUpdateNativeControl frame refers to the AcitivityIndicator

You should of course either use RunOnMainThread or even better do not use a thread at all and instead use a task that is recreated once it is completed.

NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.BindableObject.GetContext (Xamarin.Forms.BindableProperty property) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.GetValue (Xamarin.Forms.BindableProperty property) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.VisualElement.get_RotationY () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementTracker+<>c__DisplayClass1.<OnUpdateNativeControl>b__0 () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x00016] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:691
Comment 1 Udham Singh 2014-10-20 14:28:10 UTC
Could you please provide a sample apple app that demonstrate the issue and complete environment info, so that we can reproduce this issue at our end?

You can get environment info via : 'Open XS > Xamarin Studio > About Xamarin Studio > Show details'

Also can you please provide Ide info? You can get Ide logs via: 'open XS > Help > Open Log Directory > IDE.log file (with latest timestamp)'

Thanks
Comment 2 luca.barbieri 2014-10-20 14:36:29 UTC
Sorry, but the issue does not always happen, probably because it is a race condition resulting from the thread-unsafe access there.

Hence, I don't think it makes sense to provide an app to reproduce it, since it would take time and you might not be able to reproduce it anyway.

However, the stack trace alone shows that there is a bug, since it is accessing VisualElement.RotationY from a thread starting on CADisplayLinkTicker.StartThread, which is always a bug since a VisualElement must only be accessed from the UI thread.

Given the fact that it cannot be reproduced reliably, I'd expect a race condition resulting from this to be causing the NullPointerReference as well.

IDE info is irrelevant, but anyway it's 5.6.2 build 5 (and I'm of course using Xamarin Forms 1.3.0.6262-pre0 as it's the only 1.3.0 build you released).
Comment 3 Rui Marinho 2015-05-28 13:50:51 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue we would very much appreciate it. We monitor recently touched NEEDS INFO bugs so we’ll notice you attached the reproduction we’ll take it from there. 

Warm regards,
Xamarin Forms Team
Comment 4 Jason Smith [MSFT] 2016-03-18 08:43:30 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we no longer believe it affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 5 Kirill 2016-09-25 14:58:08 UTC
Hello. I have same problem. I often change BindingProperty in ViewModel and I often do it in second thread (RestApi, async methods). 

If I close page (PopAsync) when BindableProperty is changed in async method the "BindableObject.GetContext(BindableProperty property)" is thrown "System.NullReferenceException: Object reference not set to an instance of an object"

Please help me. Must I change BindableProperty in BeginInvoceInMainThread or it is Xamarin.Forms error?
Comment 6 Kirill 2016-09-25 15:13:02 UTC
Xamarin caused by: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
Xamarin.Forms.BindableObject.GetContext(BindableProperty property)<b0fc14d4e5b04749b7241d1235a68329>:0
Xamarin.Forms.BindableObject.GetValue(BindableProperty property)<b0fc14d4e5b04749b7241d1235a68329>:0
Xamarin.Forms.VisualElement.get_Width()<b0fc14d4e5b04749b7241d1235a68329>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateAnchorX()<95895bcb439e42ebb8e7134a545f1acc>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateLayout()<95895bcb439e42ebb8e7134a545f1acc>:0
Xamarin.Forms.Platform.Android.VisualElementRenderer<TElement>.UpdateLayout()<95895bcb439e42ebb8e7134a545f1acc>:0
Xamarin.Forms.Platform.Android.VisualElementRenderer<TElement>.OnLayout(bool changed, int l, int t, int r, int b)<95895bcb439e42ebb8e7134a545f1acc>:0
Xamarin.Forms.Platform.Android.ViewRenderer<TView, TNativeView>.OnLayout(bool changed, int l, int t, int r, int b)<95895bcb439e42ebb8e7134a545f1acc>:0
Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, bool p0, int p1, int p2, int p3, int p4)<2727d869763141fbae32189add254e74>:0
at (wrapper dynamic-method) System.Object:6d762c2f-39e9-4d3d-a4ef-f546fa735398 (intptr,intptr,bool,int,int,int,int)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.ViewRenderer_2.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.ViewRenderer_2.onLayout()ViewRenderer_2.java:47
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout()FormsViewGroup.java:29
md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1.onLayout()VisualElementRenderer_1.java:49
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout()FormsViewGroup.java:29
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageContainer.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageContainer.onLayout()PageContainer.java:46
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
md5270abb39e60627f0f200893b490a1ade.NavigationPageRenderer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.NavigationPageRenderer.onLayout()NavigationPageRenderer.java:63
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout()FormsViewGroup.java:29
md5270abb39e60627f0f200893b490a1ade.MasterDetailContainer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.MasterDetailContainer.onLayout()MasterDetailContainer.java:45
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.support.v4.widget.DrawerLayout.onLayout()DrawerLayout.java:1187
md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.onLayout()MasterDetailPageRenderer.java:68
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.onLayout()PlatformRenderer.java:55
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.widget.RelativeLayout.onLayout()RelativeLayout.java:1077
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.widget.FrameLayout.layoutChildren()FrameLayout.java:573
android.widget.FrameLayout.onLayout()FrameLayout.java:508
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.widget.LinearLayout.setChildFrame()LinearLayout.java:1702
android.widget.LinearLayout.layoutVertical()LinearLayout.java:1556
android.widget.LinearLayout.onLayout()LinearLayout.java:1465
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.widget.FrameLayout.layoutChildren()FrameLayout.java:573
android.widget.FrameLayout.onLayout()FrameLayout.java:508
android.view.View.layout()View.java:16695
android.view.ViewGroup.layout()ViewGroup.java:5328
android.view.ViewRootImpl.performLayout()ViewRootImpl.java:2319
android.view.ViewRootImpl.performTraversals()ViewRootImpl.java:2032
android.view.ViewRootImpl.doTraversal()ViewRootImpl.java:1191
android.view.ViewRootImpl$TraversalRunnable.run()ViewRootImpl.java:6642
android.view.Choreographer$CallbackRecord.run()Choreographer.java:777
android.view.Choreographer.doCallbacks()Choreographer.java:590
android.view.Choreographer.doFrame()Choreographer.java:560
android.view.Choreographer$FrameDisplayEventReceiver.run()Choreographer.java:763
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:145
android.app.ActivityThread.main()ActivityThread.java:5951
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1400
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1195