xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Crash on Screen rotation on Xamarin.Forms 4.6.0.772 and newer #10733

Closed ichijikuibo closed 4 years ago

ichijikuibo commented 4 years ago

Description

There is a crash in Xamarin.Forms 4.6.0.772 and newer on android during screen orientation changes. I have tested it on a blank app and it also crashes.

Rotation Crash.txt

Steps to Reproduce

  1. Rotate device 90 degrees to cause a orientation change

Expected Behavior

Screen content rotates

Actual Behavior

App crashes

Basic Information

Workaround

Roll back to version 4.6.0.726

enterprisemk commented 4 years ago

Same here - Android apps crashing on screen rotation after upgrading to: Xamarin.Forms v4.6.0.772. This includes blank android apps. iOS has no issue.

Downgrading to: v4.6.0.726. fixes the issue.

dhewitson commented 4 years ago

Same thing happening here on iOS when the application is moved to the background.

Happens on both Simulator targeting 13.4 and on an iPhone 7+ (iOS 13.4)

StackTrace:

at Xamarin.Forms.Internals.EnumerableExtensions.IndexOf[T] (System.Collections.Generic.IEnumerable`1[T] enumerable, T item) [0x00003] in :0 \n at Xamarin.Forms.Application.OnRequestedThemeChanged (Xamarin.Forms.AppThemeChangedEventArgs args) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:172 \n at Xamarin.Forms.Platform.iOS.PageRenderer.TraitCollectionDidChange (UIKit.UITraitCollection previousTraitCollection) [0x00021] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:373 \n at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)\n at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:86 \n at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:65 \n at IdentifEye.iOS.Application.Main (System.String[] args) [0x00002] in /Users/dhewitson/IdentifEye/IdentifEye/IdentifEye.iOS/Main.cs:15 "

ivanjx commented 4 years ago

Does downgrading to v4.6.0.726 fixes your issue @dhewitson ?

dhewitson commented 4 years ago

@realivanjx yes it does

tompi commented 4 years ago

Same thing happened to me today, downgraded and problem disappeared

ichijikuibo commented 4 years ago

Hadn't noticed before but I also get the same issue as @dhewitson on iOS.

jsuarezruiz commented 4 years ago

Thanks for the feedback to everyone. This PR should fix this issue: https://github.com/xamarin/Xamarin.Forms/pull/10714

jimmy-robert commented 4 years ago

Same here. Our workaround for Android until #10714 is merged:

        // MainActivity.cs

        public override void OnConfigurationChanged(Configuration newConfig)
        {
            if (Device.Flags == null)
            {
                Device.SetFlags(new List<string>());
            }

            base.OnConfigurationChanged(newConfig);
        }
PureWeen commented 4 years ago

should be fixed here https://www.nuget.org/packages/Xamarin.Forms/4.6.0.800

jdinnen commented 4 years ago

Im also seeing this crash on iOS on 4.7.0.1080 when I rotate the screen

at Xamarin.Forms.Platform.iOS.VisualElementTracker.ShouldUpdateClip () [0x00037] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:452 at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateClip () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:394 at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateNativeControl () [0x0006c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:386 at Xamarin.Forms.Platform.iOS.VisualElementTracker.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:97 at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:229 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:353 at Xamarin.Forms.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) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:461 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:318 at Xamarin.Forms.VisualElement.set_Width (System.Double value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:451 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1080 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316 at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178 at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29 at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1083 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316 at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708 at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178 at Xamarin.Forms.Platform.iOS.ViewCellRenderer+ViewTableCell.LayoutSubviews () [0x00081] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Cells\ViewCellRenderer.cs:97 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at JobTask.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\John\source\repos\JobTask\JobTask\JobTask.iOS\Main.cs:12

samhouts commented 4 years ago

@jdinnen That should be fixed by SR2, which will be out later today. Thanks for your patience!

jdinnen commented 4 years ago

@jdinnen That should be fixed by SR2, which will be out later today. Thanks for your patience!

Seems to be good in 4.7.0.1142, thank you!

procopio commented 4 years ago

Sorry but it's still happening in iOS when you have a CollectionView filled in a ContentPage. If the CollectionView has no lines this didn't happening.

Xamarin Forms: 4.8.0.1364 iPhone 11 iOS 13.7 (simulator)

2020-09-15 16:25:05.933455+0200 Rabbit2.iOS[96613:9707274] [Snapshotting] Snapshotting a view (0x7fcd0f859aa0, Xamarin_Forms_Platform_iOS_VerticalCell) that is not in a visible window requires afterScreenUpdates:YES. 2020-09-15 16:25:08.385726+0200 Rabbit2.iOS[96613:9707274] [AppCenterCrashes] ERROR: +[MSWrapperLogger MSWrapperLog:tag:level:]/10 Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Platform.iOS.VerticalCell.Measure () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\VerticalCell.cs:18 at Xamarin.Forms.Platform.iOS.TemplatedCell.PreferredLayoutAttributesFittingAttributes (UIKit.UICollectionViewLayoutAttributes layoutAttributes) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\TemplatedCell.cs:55 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at Rabbit2.iOS.Application.Main (System.String[] args) [0x00001] in /Users/joaofortes/Documents/Dev/Rabbit/Rabbit2/Rabbit2/Rabbit2.iOS/Main.cs:17 2020-09-15 16:25:08.401295+0200 Rabbit2.iOS[96613:9707274] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException) at Xamarin.Forms.Platform.iOS.VerticalCell.Measure () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\VerticalCell.cs:18 at Xamarin.Forms.Platform.iOS.TemplatedCell.PreferredLayoutAttributesFittingAttributes (UIKit.UICollectionViewLayoutAttributes layoutAttributes) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\TemplatedCell.cs:55 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at Rabbit2.iOS.Application.Main (System.String[] args) [0x00001] in /Users/joaofortes/Documents/Dev/Rabbit/Rabbit2/Rabbit2/Rabbit2.iOS/Main.cs:17

KarlSearl commented 3 years ago

Same here.

procopio commented 2 years ago

I've tried on the 5.0.0.2401 and the issue is still there.

procopio commented 2 years ago

My workaround is:

    protected override void OnSizeAllocated(double width, double height)
    {
        base.OnSizeAllocated(width, height);

        if (width != this.width || height != this.height)
        {
            this.width = width;
            this.height = height;

            // isAppeared  is set to true in OnAppearing()
            if (isAppeared && Device.RuntimePlatform == Device.iOS) // iOS roataion bug workaround
            {
                Task.Run(() =>
                {
                    isAppeared = false;
                    Task.Delay(1000).Wait();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        MainPage.Instance.Detail = CurrentPage(); // reload current page
                    });
                });

                return;
            }

            System.Diagnostics.Debug.WriteLine($"OnSizeAllocated START From(w:{this.width} h:{this.height}) To(w:{width} h:{height}) " + DateTime.Now.ToString("HH:mm:ss.fff"));

            // make your layout adjustments here...

            System.Diagnostics.Debug.WriteLine("OnSizeAllocated FINISH " + DateTime.Now.ToString("HH:mm:ss.fff"));
        }
    }