-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug, CollectionView] CollectionView crashes when ItemsSource updated too fast #9753
Comments
@RonnyBansemer Could you attach a repro sample?. I have been doing some tests to reproduce the issue but without success. |
@jsuarezruiz Sure, I tested long time, because I could not reproduce it with your repository as well. The Issue only seems to occour randomly when not consequently adding/updating collection elements on mainthread. |
I also got this issue, seems it's related to RecyclerView bug: |
@hs79hs As already mentioned, update ItemsSource of CollectionView and all properties of bound model on mainthread. Otherwise you possibly run into a race condition, because different threads try to update the CollectionView at same time. And then: BOOM, you get an exception. |
If you take the repro from #9753 (comment) and change OnAddItemExecuted to
a couple seconds of rapid clicking will crash it every time. |
@hartez Again, this is a threading problem. Updating all ui changing properties solve the issue. Is the expected behavior to be able to update and change from random thread without crash? |
@RonnyBansemer I tried and yes, if put all UI related work in main thread, this issue never happened. Thanks, this solved my problem. |
I have tried adding items on main thread and it works fine BUT if you use ItemsUpdatingScrollMode="KeepLastItemInView" in XAML, the application crashs with exception:
if you remove it from xaml, works nice but without the auto scrolling resource. |
For me Device.BeginInvokeOnMainThread on collection manipulation solve crash. Delay doens',t work. Thanks |
Similar issue here when adding/updating/removing items in observed collection (ItemSource of the CollectionView). The exception is "Java.Lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder".
Another "workaround" to be added to the list is to: create a copy of the observed collection, clear the observed collection, work on the copy and at the end add back to the observed from the copy like so:
Still a waste of time/resources though. |
@inimirpaz I have the same crash as you, but using a temporary collection does not resolve it :( I want to update the collection items. |
This is the same core issue as reported in #10735. There are actually two different bugs demonstrated here:
We have a fix in progress (#10765), but we're still reviewing it. In the meantime, as has been mentioned upthread, you can work around the first issue by making sure that you are on the main thread when adding items to your ItemsSource. You can do this by chekcing Device.IsInvokeRequired and using Device.BeginInvokeOnMainThread. The second issue may require a separate fix; I'll be taking a look at that tomorrow. |
@hartez What I have is |
The below workaround solve my problem, maybe you want try: public ObservableCollection YourItemSource { get; private set; } Instead of: I'm using: |
I have the same problem. What's the solution? |
@Cacuci The fix was done in this Pull Request: ab55162 And it is available in Xamarin.Forms v4.8.0-Pre2 |
seems that just hit the same or related problem. at least workaround helped page setup app hungs (somewhere outside of my code) on second switch of radiobuttons sorted it out with temporary collection the same problem was on this page with 2 checkboxes, and continues after checkboxes were replaced with radiobuttons |
Description
When CollectionView is bound to a ObservableCollection and it is updated before display fade in animation has finished it will crash.
Steps to Reproduce
Basic Information
Exception Log
Workaround
-> Update all CollectionView changing properties on main thread.
-> Throttle elements added to observable collection interval by 250ms.
The text was updated successfully, but these errors were encountered: