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

[Android] ObjectDisposedException with CarouselView #2637

Closed
Magendanz opened this issue May 8, 2018 · 12 comments
Closed

[Android] ObjectDisposedException with CarouselView #2637

Magendanz opened this issue May 8, 2018 · 12 comments

Comments

@Magendanz
Copy link

Description

When using alexrainman's CarouselView, I'm seeing pretty regular ObjectDisposedExceptions on Android. I don't see the problem with CarouselPage, but needed to switch to CarouselView for virtualization.

The crash is relatively rare (1 in 40), so I don't have consistent set of repo steps. It usually follows a Picker selection.

Note: This has been split off as a separate bug from Issue #2406, based on guidance from @hartez. There are at least three other related issues, but this one's specifically dealing with CarouselView.

Steps to Reproduce

  1. Take a project that's currently using CarouselPage, with the ItemTemplate including bound child controls like Picker, Editor and ListView.
  2. Convert it to use alexrainman's CarouselView (which is currently being integrated into Xamarin.Forms in the feature-carouselview branch).
  3. Swipe left and right through pages, making updates using the controls bound to the collection in ItemsSource.

Expected Behavior

We should see exactly the same behavior as with CarouselPage, but with improved performance due to UI virtualization.

Actual Behavior

Performance is much improved, but app will crash every hour or so given typical use.

Basic Information

This problem only occurs on Android. I've tested iOS builds and they seem fine. I have not yet been able to build using the feature-carouselview branch, but am very curious as to whether it's affected.

  • Version with issue: Xamarin.Forms v2.5.0.280555
  • IDE: VS 2017 15.6.7
  • Platform Target Frameworks:
    • iOS: 9.0 or later
    • Android: Target SDK Android 8.1 (Oreo), Minimum SDK Android 5.0 (Lollipop)
  • Android Support Library Version: 8.2.0.16
  • Nuget Packages: CarouselView.FormsPlugin v5.2.0
  • Affected Devices: Most running Android 8.1 (Oreo)

Sample stacktrace follows:

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Widget.EditText'.
JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
TextView.set_HintFormatted (Java.Lang.ICharSequence value)
TextView.set_Hint (System.String value)
PickerRenderer.UpdatePicker ()
PickerRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
BindableObject.OnPropertyChanged (System.String propertyName)
Element.OnPropertyChanged (System.String propertyName)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
Picker.set_SelectedIndex (System.Int32 value)
Picker.UpdateSelectedIndex (System.Object selectedItem)
Picker.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
BindingExpression.Apply (System.Boolean fromTarget)
BindingExpression+BindingExpressionPart.b__47_0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.0ceb0ba0-9872-4642-8dc3-2eb79185de62(intptr,intptr)

@AndreiMisiukevich

This comment has been minimized.

@deepesh002
Copy link

#2793 created as suggested

@PureWeen
Copy link
Contributor

@Magendanz do you have a repro for this by chance? I've tried a few random variations of carouselview with pickers and bindings and I'm not able to cause the above exception

I'm curious what your layout and binding looks like

@PureWeen PureWeen changed the title ObjectDisposedException on Android with alexrainman's CarouselView [Android] ObjectDisposedException with alexrainman's CarouselView May 23, 2018
@Magendanz
Copy link
Author

Magendanz commented May 23, 2018

Not a consistent repro case, no. In the field, I would receive the exception after about 20 mins to an hour of use. Typically, I'd update records with the dropdown every few minutes.

HouseholdDetailPage.zip

@PureWeen
Copy link
Contributor

@Magendanz looking at the stack trace I'm guessing there's an index change on the picker right as the page is changing

I'll add some checks into the PickerRenderer but I'm curious if you just create a custom PickerRenderer yourself that looks something like below if that will fix your particular issue

	public class CustomPickerRenderer : PickerRenderer
	{
		bool isDisposed = false;
		public CustomPickerRenderer(Context context) : base(context)
		{
		}


		protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if(!isDisposed)
				base.OnElementPropertyChanged(sender, e);
		}
		protected override void Dispose(bool disposing)
		{
			isDisposed = true;
			base.Dispose(disposing);
		}
	}

@Magendanz
Copy link
Author

Magendanz commented May 24, 2018

Okay, I've implemented this and will exercise in the field tomorrow to see if it fixes the crash. However, I am getting a version of the PickerRenderer with a dramatically different appearance that's much slower to use. Is there any way to restore the original one?

picker-before
picker-after

@PureWeen
Copy link
Contributor

PureWeen commented May 25, 2018

Hmm a few things

  1. that's odd and I'll need to test that locally with the picker
  2. my suggestion was probably misguided :-/ but you could still use what I paste to add a try catch for now
  3. I've attached a nuget package from our carousel_view branch that has the latest iteration of this carouselview and I'm curious if you're still seeing that issue with this nuget

Xamarin.Forms.9.9.9.zip

@Magendanz
Copy link
Author

BTW, I've checked the CustomPickerRenderer fix in the field, and am still receiving the ObjectDisposedExceptions. I'll try the nuget package next.

@PureWeen PureWeen added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Jun 11, 2018
@Magendanz
Copy link
Author

So, the NuGet package from the feature_carouselview branch seems to be working, but I'll exercise it in the field tomorrow to confirm. (It's also the cleanest implementation so far, mirroring ListView nicely.)

The only problem I have is that there's an issue on iOS where the first item selected is blank, even when swiping back to it later. This may have been fixed in the last 18 days, though. Is there a nightly feed for this feature branch or instructions somewhere for building a .nupkg of my own from the latest source?

@Magendanz
Copy link
Author

Also, setting SelectedItem doesn't work in that NuGet package you sent me, but setting Position does and that suffices as a workaround. I'm anxious to build a new package from the latest source.

@Magendanz
Copy link
Author

Unfortunately, the NuGet package failed our field tests. We're still getting the occasional System.ObjectDisposedException. Here's a crash log:

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Widget.EditText'.

  1. JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
  2. JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
  3. TextView.set_HintFormatted (Java.Lang.ICharSequence value)
  4. TextView.set_Hint (System.String value)
  5. PickerRenderer.UpdatePicker ()
  6. PickerRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
  7. (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
  8. BindableObject.OnPropertyChanged (System.String propertyName)
  9. Element.OnPropertyChanged (System.String propertyName)
  10. BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
  11. BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
  12. BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
  13. BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
  14. Picker.set_SelectedIndex (System.Int32 value)
  15. Picker.UpdateSelectedIndex (System.Object selectedItem)
  16. Picker.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue)
  17. BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
  18. BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
  19. BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
  20. BindingExpression.Apply (System.Boolean fromTarget)
  21. BindingExpression+BindingExpressionPart.b__49_0 ()
  22. Thread+RunnableImplementor.Run ()
  23. IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
  24. (wrapper dynamic-method) System.Object.a3a963ef-e7cb-417d-bc3d-67aeeb3b4ea5(intptr,intptr)

@PureWeen PureWeen removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Jun 14, 2018
@Magendanz Magendanz changed the title [Android] ObjectDisposedException with alexrainman's CarouselView [Android] ObjectDisposedException with CarouselView Jun 19, 2018
@StephaneDelcroix
Copy link
Member

we'd like to help, but we do not maintain or support alex's carousel view. we will provide a supported control that will allow that in 4.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants