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

[Bug] [iOS] Change Device Orientation Causes Crash #15232

Open
melvyniandrag opened this issue Mar 16, 2022 · 7 comments
Open

[Bug] [iOS] Change Device Orientation Causes Crash #15232

melvyniandrag opened this issue Mar 16, 2022 · 7 comments
Labels
a/collectionview a/listview Problems with the ListView/TableView p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛

Comments

@melvyniandrag
Copy link

Description

Rotating screen with a CollectionView causes crash along with an error about VerticalCell.Measure. By tweaking the code I have been able to produce other errors, but all are related to Xamarin.iOS and something to do with the CollectionView. Note: Also crashes a ListView.

This issue was documented by @procopio and @KarlSearl in 2020, but the ticket was closed. See ticket #10733.

Steps to Reproduce

Download the tiny sample code I linked below, compile, run, and rotate the screen on your ios device (I'm testing on an iPhone 11 ). The app crashes. Please see the short video I put on youtube demoing the crash.

-OR-

  1. Create a small app with a CollectionView on a ContentPage.
  2. Add a few elements to the CollectionView
  3. Override OnSizeAllocated to handle screen orientation changes as described here in the Grid section
  4. Launch app
  5. Rotate Screen
  6. Crash.

Expected Behavior

Items on screen should reorganize themselves as I specify in OnSizeAllocated. This is the behavior on Android, Windows10, and Windows11.

Actual Behavior

App works on Android and Windows, but crashes on iOS.

Basic Information

  • Version with issue: 5.0.0.2337
  • Last known good version: None
  • Platform Target Frameworks:
    • iOS: 15.2

Environment

Show/Hide Visual Studio info
=== Visual Studio Community 2019 for Mac ===

Version 8.10.20 (build 0)
Installation UUID: 6432807e-7e5c-4af4-af83-99aec826af15
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000162

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.162 (2020-02/2ca650f1f62) (64-bit)
	Package version: 612000162

=== Roslyn (Language Service) ===

3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb

=== NuGet ===

Version: 5.9.0.7134

=== .NET SDK (x64) ===

SDK: /usr/local/share/dotnet/sdk/5.0.406/Sdks
SDK Versions:
	8.0.406
	5.0.401
	3.1.417
	3.1.413
	3.1.200
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.15
	5.0.10
	3.1.23
	3.1.19
	3.1.2
	2.1.23
	2.1.17

=== .NET Core 3.1 SDK ===

SDK: 3.1.417

=== .NET 5.0 SDK ===

SDK: 5.0.406

=== Xamarin.Profiler ===

Version: 1.6.13.11
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Not Installed

=== Eclipse Temurin JDK ===

Java SDK: Not Found

=== Android SDK Manager ===

Version: 16.10.0.13
Hash: 1b81df5
Branch: remotes/origin/d16-10
Build date: 2021-11-12 01:17:32 UTC

=== Android Device Manager ===

Version: 16.10.0.15
Hash: 89dcc0b
Branch: remotes/origin/d16-10
Build date: 2021-11-12 01:17:52 UTC

=== Apple Developer Tools ===

Xcode 13.2.1 (19586)
Build 13C100

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 15.6.0.3 (Visual Studio Community)
Hash: caa899d24
Branch: d17-1
Build date: 2022-01-16 21:16:56-0500

=== Xamarin Designer ===

Version: 16.11.0.60
Hash: 56f9b80b0
Branch: remotes/origin/d16-11
Build date: 2021-12-15 02:44:16 UTC

=== Build Information ===

Release ID: 810200000
Git revision: 1cfa1b1730b1da536e228f20c90f8649eed4e327
Build date: 2022-03-02 13:03:18-05
Build branch: release-8.10

=== Operating System ===

Mac OS X 11.6.4
Darwin 20.6.0 Darwin Kernel Version 20.6.0
    Wed Jan 12 22:22:42 PST 2022
    root:xnu-7195.141.19~2/RELEASE_X86_64 x86_64


Screenshots

Better that a Screenshot, here is a video showing the crash

Reproduction Link

Here is a tiny repo illustrating the issue

Workaround

No work around yet.

@melvyniandrag melvyniandrag added s/unverified New report that has yet to be verified t/bug 🐛 labels Mar 16, 2022
@jfversluis jfversluis added p/iOS 🍎 a/listview Problems with the ListView/TableView a/collectionview labels Mar 18, 2022
@jfversluis
Copy link
Member

Hey @melvyniandrag, a PR (#15300) for this is open now, would you be able to grab the NuGet as described here and let us know if this fixes this issue? That will greatly speed up the review process. Make sure to grab the actual version mentioned in the PR, other versions on that feed will not include this fix.

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

@melvyniandrag
Copy link
Author

melvyniandrag commented Apr 8, 2022

Hi @jfversluis thanks for giving this some attention. Unfortunately this patch does not resolve the issue and might make the situation worse. There is still a bug when changing the device orientation from portrait -> landscape.
And now the application will not start in landscape mode.

landscapeWontLaunch.txt
portraitToLandscapeCrash.txt

Attached are the logs for the two issues.

The landscape log is very long, but near the end it just repeats this error message:
022-04-08 17:27:38.063 CollectionViewTest.iOS[2280:1076672] The behavior of the UICollectionViewFlowLayout is not defined because: 2022-04-08 17:27:38.063 CollectionViewTest.iOS[2280:1076672] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values. 2022-04-08 17:27:38.063 CollectionViewTest.iOS[2280:1076672] Please check the values returned by the delegate.

@melvyniandrag
Copy link
Author

melvyniandrag commented Apr 8, 2022

Hello again, and just as a sanity check I am showing my installed Nuget packages, which shows version 5.0.0.8133, which[ is the version indicated here in the Pull Request](https://github.com/xamarin/Xamarin.Forms/pull/15300/checks?check_run_id=5886717107
Screen Shot 2022-04-08 at 5 38 03 PM
)

@jfversluis
Copy link
Member

Hehe ok so far for my fix attempt then, sorry! Need to do further investigation :) Thanks for testing!

@procopio
Copy link

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

@procopio
Copy link

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"));
        }
    }

@melvyniandrag
Copy link
Author

Hi @procopio Thanks for the workaround!
And
Thanks @jfversluis for the attention to this issue.

Unfortunately the workaround above isn't a great solution for me and my team. We'll consider factoring this into our app, but a cleaner platform-agnostic solution would be much preferred.

Thanks again guys I'll keep an eye on this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview a/listview Problems with the ListView/TableView p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants