From c736078c284955e9e97451cb91b25d7f0bbda6b6 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sun, 30 Oct 2022 16:46:31 -0400 Subject: [PATCH 1/2] _itemsSource may be null I'm seeing a NullReferenceException in this method. There are no guards against `_itemsSource` being null, so dereferencing it to get its `Count` seems likely to be the problem. --- .../Handlers/Items/Android/CarouselViewLoopManager.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs b/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs index 53bade9e2853..47f1a41fd7ee 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs @@ -14,6 +14,8 @@ public void CenterIfNeeded(RecyclerView recyclerView, bool isHorizontal) { if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager)) return; + if (_itemsSource is null) + return; var itemSourceCount = _itemsSource.Count; @@ -43,9 +45,11 @@ public int GetGoToIndex(RecyclerView recyclerView, int carouselPosition, int new { if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager)) return -1; - + if (_itemsSource is null) + return -1; + var currentCarouselPosition = carouselPosition; - var itemSourceCount = _itemsSource.Count; + var itemSourceCount = _itemsSource.Count var diffToStart = currentCarouselPosition + (itemSourceCount - newPosition); var diffToEnd = itemSourceCount - currentCarouselPosition + newPosition; From d7621c74e3c20404d3e23ac977fe3c44b867817a Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sun, 30 Oct 2022 16:54:59 -0400 Subject: [PATCH 2/2] fix dropped semicolon --- .../src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs b/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs index 47f1a41fd7ee..78879067ab01 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/CarouselViewLoopManager.cs @@ -49,7 +49,7 @@ public int GetGoToIndex(RecyclerView recyclerView, int carouselPosition, int new return -1; var currentCarouselPosition = carouselPosition; - var itemSourceCount = _itemsSource.Count + var itemSourceCount = _itemsSource.Count; var diffToStart = currentCarouselPosition + (itemSourceCount - newPosition); var diffToEnd = itemSourceCount - currentCarouselPosition + newPosition;