Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] [iOS] CollectionView crashes the Xamarin Forms App

Open p3pp33ng opened this issue 3 years ago • 12 comments

Description

I have a Xamarin Forms app that has a collectionview that loads in items from a API as you scroll down in the collectionview. Sometimes when i scroll in the iOS app i get an error and the app crashes. This issue only occurs on iOS.

Steps to Reproduce

  1. Navigate to Page with collectionview
  2. Scroll down on the Page
  3. Error occur and app crashes

Expected Behavior

No crash just keep scrolling

Actual Behavior

Sometimes it crashes the app.

Basic Information

  • Version with issue: 5.0.0.2401
  • Platform Target Frameworks:
    • iOS: 15.4

Environment

This is the error i get and it seems that it thinks that the itemssource in the collectionview is empty and then when it finds out its not empty and then crashes.

{System.NullReferenceException: Object reference not set to an instance of an object  at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].CheckForEmptySource () [0x00028]
 in D:\a\_work\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewController.cs:117   
at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].NumberOfSections (UIKit.UICollectionView collectionView) [0x00000] in D:\a\_work\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewController.cs:256
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper(intptr,intptr)  
at UIKit.UICollectionViewLayout.PrepareLayout () [0x00023] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UICollectionViewLayout.g.cs:496
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.PrepareLayout () [0x00000] in D:\a\_work\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewLayout.cs:415   
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)  
at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:85
at <ProjectName>.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\JesperEngdahl\source\repos\<ProjectName>\Main.cs:17 }

p3pp33ng avatar May 23 '22 10:05 p3pp33ng

Yup I can confirm same issue here, glad to discover I'm not the only one but unfortunately the iOS issues keep coming 😢 I've only tested on iOS 15.0 as well.

LeoJHarris avatar May 25 '22 00:05 LeoJHarris

@p3pp33ng are you able to provide a sample that replicates the issue? I tried to reproduce this issue with a stripped out version of the same app. If you provide a sample app that can reproduce this issue a fix will arrive sooner.

LeoJHarris avatar May 25 '22 03:05 LeoJHarris

I've managed to reproduce this issue with the below sample and I run the app on an emulator using an iPhone 12 Pro 15.5

XamApp.zip

Simulator Screen Shot - iPhone 12 Pro Max - 2022-05-26 at 08 57 12

Simulator Screen Shot - iPhone 12 Pro Max - 2022-05-26 at 08 57 15

If you swipe the row in blue background and tap the remove the crash should occur

LeoJHarris avatar May 25 '22 21:05 LeoJHarris

Hello @LeoJHarris, First and foremost very sorry for the late reply to your incredible contribution of building a sample to test with for this issue. I havent had the time to test it out, but will make it a priority first thing next week, hopefully this will help to find the underlaying cause of the shared problem we have.

Happy weekend and i will follow up this under next week.

p3pp33ng avatar May 27 '22 16:05 p3pp33ng

The issue could be with the fact that you have SwipeView within Collectionview. I experienced many issues with this, which lead me to have separate layouts for iOS and Android. I utilized the CarouselView instead in a way that mimics the swipeview behavior.

ccsousa01 avatar Jun 15 '22 13:06 ccsousa01

I was facing a similar case in UWP, where the app crashed when I tried to programatically scroll the collection view right when it becomes visible. The issue resolved when I put the CollectionView inside a RefreshView

adesypri avatar Aug 03 '22 09:08 adesypri

I have the same problem on iOS. Any ideas how for fix/workaround?

AlexandrNikulin avatar Aug 10 '22 09:08 AlexandrNikulin

I have the same issue on iOS.

I have a CollectionView inside a RefreshView. The items template have a SwipeView. After many times refreshing the collection, it crashes with the same error. Removing the SwipeView from the items template doesn't help.

Papa-Tori avatar Sep 30 '22 07:09 Papa-Tori

Same here.

jtorvald avatar Jan 02 '23 20:01 jtorvald

The changes mentioned in the commit referenced above already exist now in Xamarin.Forms' repo.

Please try the latest release of Xamarin.Forms to see if it resolves your issue, if not, please provide a more up to date and smaller reproduction project of the issue.

Redth avatar Apr 25 '23 14:04 Redth

@Redth yeah I noticed the PR after I started working on the fix. I believe this issue can be closed.

jtorvald avatar Apr 25 '23 14:04 jtorvald

@Redth I can confirm I am not seeing this crash from upgrading from 5.0.0.2478 to 5.0.0.2622

LeoJHarris avatar Nov 20 '23 04:11 LeoJHarris