alexrainman / SegmentedControl

MIT License
86 stars 38 forks source link

Object Disposed Exception. Crash. Android only #44

Closed alexlobanov closed 7 years ago

alexlobanov commented 7 years ago

Hi,

Thanks a lot for this great library and for your work on this.

Have one question, I used this plugin in the one app. Use this in one of the pages in the TabPage control.

Issue:

So as I saw on HockeyApp, some users have crash (android users only). This crash is very randomly appears, I think it's just in 1 of the 20-30 cases. I spent two hours trying to reproduce this, and I got two crashes (when page with this control creating).

So this is one of the crash reports (more frequently issue):

Object name: 'SegmentedControl.FormsPlugin.Android.SegmentedControlRenderer'.
Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable self)<db8d17e553074ec7ae1f02c6b1825c82>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)<db8d17e553074ec7ae1f02c6b1825c82>:0
Android.Views.View.get_IsInLayout()<d83ea4fb7cbc42c5b768e929559b8bce>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.MaybeRequestLayout()<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.HandleRedrawNeeded(object sender, EventArg<T> e)<1481f85a917c4f2b882ea161e9bc082f>:0
System.EventHandler<EventArg<VisualElement>>.invoke_void_object_TEventArgs(object, EventArg<VisualElement>)(wrapper delegate-invoke)
Xamarin.Forms.VisualElement.BatchCommit()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.set_Bounds(Rectangle value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.Layout(Rectangle bounds)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(View child, Rectangle region, SizeRequest childSizeRequest)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.StackLayout.LayoutChildren(double x, double y, double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.UpdateChildrenLayout()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.OnSizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.<>c.<OnChildMeasureInvalidated>b__39_0()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Java.Lang.Thread.RunnableImplementor.Run()<d83ea4fb7cbc42c5b768e929559b8bce>:0
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)<d83ea4fb7cbc42c5b768e929559b8bce>:0
at (wrapper dynamic-method) System.Object:11816c67-5009-414c-979c-fb150a01ba30 (intptr,intptr)
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:135
android.app.ActivityThread.main()ActivityThread.java:5276
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:911
com.android.internal.os.ZygoteInit.main()

And one more (more detailed):

Object name: 'SegmentedControl.FormsPlugin.Android.SegmentedControlRenderer'.
Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable self)<bd30a18775d94dc8b6263aecd1ca9077>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)<bd30a18775d94dc8b6263aecd1ca9077>:0
Android.Views.View.get_IsInLayout()<d855bac285f44dda8a0d8510b679b1e2>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.MaybeRequestLayout()<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.Platform.Android.VisualElementTracker.HandleRedrawNeeded(object sender, EventArg<T> e)<1481f85a917c4f2b882ea161e9bc082f>:0
System.EventHandler<EventArg<VisualElement>>.invoke_void_object_TEventArgs(object, EventArg<VisualElement>)(wrapper delegate-invoke)
Xamarin.Forms.VisualElement.BatchCommit()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.set_Bounds(Rectangle value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.Layout(Rectangle bounds)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(View child, Rectangle region, SizeRequest childSizeRequest)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.StackLayout.LayoutChildren(double x, double y, double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.UpdateChildrenLayout()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.OnSizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SetSize(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.set_Bounds(Rectangle value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.Layout(Rectangle bounds)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rectangle region)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.LayoutChildren(double x, double y, double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.UpdateChildrenLayout()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.OnSizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SetSize(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.set_Bounds(Rectangle value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.Layout(Rectangle bounds)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rectangle region)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.LayoutChildren(double x, double y, double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.UpdateChildrenLayout()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.OnSizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.ForceLayout()<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Page.Xamarin.Forms.IPageController.set_ContainerArea(Rectangle value)<0f1ce60dbc6b4e24af01294c7acf41c6>:0
Xamarin.Forms.Platform.Android.AppCompat.TabbedPageRenderer.OnLayout(bool changed, int l, int t, int r, int b)<1481f85a917c4f2b882ea161e9bc082f>:0
Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, bool p0, int p1, int p2, int p3, int p4)<509b941eb6c9409ea563416977a01cbe>:0
at (wrapper dynamic-method) System.Object:0888fb81-3268-4f3d-9c23-3e07ee8cc6c5 (intptr,intptr,bool,int,int,int,int)
md5270abb39e60627f0f200893b490a1ade.TabbedPageRenderer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.TabbedPageRenderer.onLayout()TabbedPageRenderer.java:71
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout()FormsViewGroup.java:29
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageContainer.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageContainer.onLayout()PageContainer.java:54
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
md5270abb39e60627f0f200893b490a1ade.NavigationPageRenderer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.NavigationPageRenderer.onLayout()NavigationPageRenderer.java:65
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout()FormsViewGroup.java:29
md5270abb39e60627f0f200893b490a1ade.MasterDetailContainer.n_onLayout(Native Method)
md5270abb39e60627f0f200893b490a1ade.MasterDetailContainer.onLayout()MasterDetailContainer.java:53
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
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:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.n_onLayout(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.onLayout()PlatformRenderer.java:63
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
android.widget.RelativeLayout.onLayout()RelativeLayout.java:1076
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
android.widget.FrameLayout.layoutChildren()FrameLayout.java:579
android.widget.FrameLayout.onLayout()FrameLayout.java:514
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
android.widget.LinearLayout.setChildFrame()LinearLayout.java:1734
android.widget.LinearLayout.layoutVertical()LinearLayout.java:1588
android.widget.LinearLayout.onLayout()LinearLayout.java:1497
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
android.widget.FrameLayout.layoutChildren()FrameLayout.java:579
android.widget.FrameLayout.onLayout()FrameLayout.java:514
android.view.View.layout()View.java:15728
android.view.ViewGroup.layout()ViewGroup.java:5050
android.view.ViewRootImpl.performLayout()ViewRootImpl.java:2113
android.view.ViewRootImpl.performTraversals()ViewRootImpl.java:1867
android.view.ViewRootImpl.doTraversal()ViewRootImpl.java:1065
android.view.ViewRootImpl$TraversalRunnable.run()ViewRootImpl.java:6037
android.view.Choreographer$CallbackRecord.run()Choreographer.java:793
android.view.Choreographer.doCallbacks()Choreographer.java:606
android.view.Choreographer.doFrame()Choreographer.java:575
android.view.Choreographer$FrameDisplayEventReceiver.run()Choreographer.java:779
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:135
android.app.ActivityThread.main()ActivityThread.java:5569
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:931
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:726

Expected scenario:

App should not crash.

Environment versions:

SegmentedControl Version - 1.3.1 Xamarin.Android - Version: 7.3.1.2 (Visual Studio Enterprise) Xamarin Forms - 2.3.4.247 Operating System - Mac OS X 10.12.5

Do you have some ideas how to resolve this?

Thanks a lot.

alexrainman commented 7 years ago

Is this solved?

alexlobanov commented 7 years ago

We waiting confirmation from users. I'm trying to fix this in elegant way.. but seems like I can't do this. But after I change some logic in the Dispose() method, and also override IsInLayout property as I as this on the stackstrace. On the property I check java handle reference link for null, like this:

public override bool IsInLayout
        {
            get
            {
                if (nativeControl.Handle == IntPtr.Zero)
                {
                    return false;
                }
                return base.IsInLayout;
            }
        }

This is seems like fixed issue / made it more rare.. but of course, this is not right way to fix this.

mikegottlieb commented 7 years ago

I'm also seeing this in the latest version

alexlobanov commented 7 years ago

@mikegottlieb did you know version that don't have this issue?

@alexrainman I also saw some new crashes on this week, this start to be more much less often after I create those patch, and when I change GC collector for Android to "new" instead of "tarjan" : MONO_GC_PARAMS=bridge-implementation=new

Please read this: Garbage Collection Android. Xamarin.com

Thanks for any help!

mikegottlieb commented 7 years ago

I switched back to version 1.2.4. I also ended up rolling all of my upgrades include my Xamarin.Forms version back down because I was experiencing a lot of problems.

alexrainman commented 7 years ago

@alexlobanov when you say TabPage are you talking about TabbedPage or this plugin https://www.nuget.org/packages/CwwOnline.TabbedPageExt.Xamarin/?

Because if it's the plugin, then i cannot do anything about it. I have it working on Xamarin.Forms TabbedPage.

alexlobanov commented 7 years ago

@alexrainman I used only Xamarin.Forms TabbedPage. I switched back to version 1.2.4 as @mikegottlieb suggested, I will report back if this is fix issue.

Thanks.

alexrainman commented 7 years ago

OK

VincentH-Net commented 6 years ago

I got this error today with the latest release NuGet 2.0.1. Latest Xamarin Forms stable. Occurred when rotating phone while on a page that was pushed on top of the page containing the segmented control.

Please reopen & fix?

Stack trace: Message: Cannot access a disposed object. Object name: 'SegmentedControl.FormsPlugin.Android.SegmentedControlRenderer'. Java.Interop.JniPeerMembers.AssertSelf(Java.Interop.IJavaPeerable self) in <3cb12bce834a498199b2be6cd3e00922>:0 Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod(System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) in <3cb12bce834a498199b2be6cd3e00922>:0 Android.Views.View.get_IsInLayout() in :0 Xamarin.Forms.Platform.Android.VisualElementTracker.MaybeRequestLayout() in :0 Xamarin.Forms.Platform.Android.VisualElementTracker.HandleRedrawNeeded(System.Object sender, Xamarin.Forms.Internals.EventArg`1[T] e) in :0 Xamarin.Forms.VisualElement.BatchCommit() in :0 Xamarin.Forms.VisualElement.set_Bounds(Xamarin.Forms.Rectangle value) in :0 Xamarin.Forms.VisualElement.Layout(Xamarin.Forms.Rectangle bounds) in :0 Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) in :0 Xamarin.Forms.Grid.LayoutChildren(System.Double x, System.Double y, System.Double width, System.Double height) in :0 Xamarin.Forms.Layout.UpdateChildrenLayout() in :0 Xamarin.Forms.Layout.OnSizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.SizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.SetSize(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.set_Bounds(Xamarin.Forms.Rectangle value) in :0 Xamarin.Forms.VisualElement.Layout(Xamarin.Forms.Rectangle bounds) in :0 Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) in :0 Xamarin.Forms.Page.LayoutChildren(System.Double x, System.Double y, System.Double width, System.Double height) in :0 Xamarin.Forms.Page.UpdateChildrenLayout() in :0 Xamarin.Forms.Page.OnSizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.SizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.SetSize(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.set_Bounds(Xamarin.Forms.Rectangle value) in :0 Xamarin.Forms.VisualElement.Layout(Xamarin.Forms.Rectangle bounds) in :0 Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) in :0 Xamarin.Forms.Page.LayoutChildren(System.Double x, System.Double y, System.Double width, System.Double height) in :0 Xamarin.Forms.Page.UpdateChildrenLayout() in :0 Xamarin.Forms.Page.OnSizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.VisualElement.SizeAllocated(System.Double width, System.Double height) in :0 Xamarin.Forms.Page.ForceLayout() in :0 Xamarin.Forms.Page.set_ContainerArea(Xamarin.Forms.Rectangle value) in :0 Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnLayout(System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) in :0 Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII(System.IntPtr jnienv, System.IntPtr native__this, System.Boolean p0, System.Int32 p1, System.Int32 p2, System.Int32 p3, System.Int32 p4) in <5beae0e5a0164ba59598bb6ee5fad667>:0

darylwatts commented 6 years ago

I also have the exact same issue as @VincentH-Net described above, same conditions, same error. Using latest Nuget and Latest Forms version. @alexrainman Please can this issue be reopened and fixed?

JannieT commented 6 years ago

For me it crashes on Android when I use the control on a master-detail page. Reverting back to ver 1.2.4 is a very poor workaround, because that version does not apply the Tint color consistently. @alexrainman please re-open.