When CollectionView is bound to a ObservableCollection and it is updated before display fade in animation has finished it will crash.
Exception #0: Inconsistency detected. Invalid item position 48(offset:49).state:49 crc643f46942d9dd1fff9.CollectionViewRenderer{ba0eea9 VFED..... ......ID 0,0-394,652 #1d1}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@16bfd3a, layout:androidx.recyclerview.widget.LinearLayoutManager@3183dc7, context:android.view.ContextThemeWrapper@42bf230
--- End of managed Java.Lang.IndexOutOfBoundsException stack trace ---
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 48(offset:49).state:49 crc643f46942d9dd1fff9.CollectionViewRenderer{ba0eea9 VFED..... ......ID 0,0-394,652 #1d1}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@16bfd3a, layout:androidx.recyclerview.widget.LinearLayoutManager@3183dc7, context:android.view.ContextThemeWrapper@42bf230
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6183)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:4085)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3849)
at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1897)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5260)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:933)
at android.view.Choreographer.doCallbacks(Choreographer.java:742)
at android.view.Choreographer.doFrame(Choreographer.java:671)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:919)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6623)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
-> Update all CollectionView changing properties on main thread.
-> Throttle elements added to observable collection interval by 250ms.
@RonnyBansemer Could you attach a repro sample?. I have been doing some tests to reproduce the issue but without success.
Issue9753.zip
@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.
Issue9753.zip
I also got this issue, seems it's related to RecyclerView bug:
https://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in
https://forums.xamarin.com/discussion/176229/exception-thrown-by-collectionview-while-implementing-as-staggeredgridlayoutmanager
@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 https://github.com/xamarin/Xamarin.Forms/issues/9753#issuecomment-592044314 and change OnAddItemExecuted to
async Task OnAddItemExecuted(object item)
{
var data = ((string)item).Split(',');
await Task.Delay(TimeSpan.FromMilliseconds(Random.Next(10, 250)));
Items.Add(new Product
{
Height = Random.Next(40, 150),
Description = data[0],
Number = data[1],
Quantity = 1,
Price = decimal.Parse(data[2])
});
}
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:
Java.Lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 229(offset:231).state:231 crc643f46942d9dd1fff9.CollectionViewRenderer{b16867d VFED.V... ......ID 20,20-1420,1932 #8}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@9983bec, layout:android.support.v7.widget.LinearLayoutManager@a998a6c, context:android.view.ContextThemeWrapper@2474d4
at java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 229(offset:231).state:231 crc643f46942d9dd1fff9.CollectionViewRenderer{b16867d VFED.V... ......ID 20,20-1420,1932 #8}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@9983bec, layout:android.support.v7.widget.LinearLayoutManager@a998a6c, context:android.view.ContextThemeWrapper@2474d4
at at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5923)
at at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1888)
at at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5044)
at at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at at android.view.Choreographer.doFrame(Choreographer.java:635)
at at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at at android.os.Handler.handleCallback(Handler.java:751)
at at android.os.Handler.dispatchMessage(Handler.java:95)
at at android.os.Looper.loop(Looper.java:154)
at at android.app.ActivityThread.main(ActivityThread.java:6682)
at at java.lang.reflect.Method.invoke(Native Method)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
if you remove it from xaml, works nice but without the auto scrolling resource.
@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.
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".
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder{7860c34 position=3 id=-1, oldPos=2, pLpos:2 scrap [attachedScrap] tmpDetached not recyclable(1) no parent} crc643f46942d9dd1fff9.CollectionViewRenderer{70072e9 VFED..... ......ID 0,171-1080,1585 #a8}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@a7d829c, layout:androidx.recyclerview.widget.GridLayoutManager@fa62a46, context:android.view.ContextThemeWrapper@181df70
[MonoDroid] at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
[MonoDroid] at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
[MonoDroid] at AndroidX.RecyclerView.Widget.RecyclerView.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0006f] in D:\a\1\s\generated\androidx.recyclerview.recyclerview\obj\Release\monoandroid90\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:13220
[MonoDroid] at Xamarin.Forms.Platform.Android.ItemsViewRenderer`3[TItemsView,TAdapter,TItemsViewSource].OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ItemsViewRenderer.cs:68
[MonoDroid] at AndroidX.RecyclerView.Widget.RecyclerView.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00008] in D:\a\1\s\generated\androidx.recyclerview.recyclerview\obj\Release\monoandroid90\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:13204
[MonoDroid] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.107(intptr,intptr,bool,int,int,int,int)
[MonoDroid] --- End of managed Java.Lang.IndexOutOfBoundsException stack trace ---
[MonoDroid] java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder{7860c34 position=3 id=-1, oldPos=2, pLpos:2 scrap [attachedScrap] tmpDetached not recyclable(1) no parent} crc643f46942d9dd1fff9.CollectionViewRenderer{70072e9 VFED..... ......ID 0,171-1080,1585 #a8}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@a7d829c, layout:androidx.recyclerview.widget.GridLayoutManager@fa62a46, context:android.view.ContextThemeWrapper@181df70
[MonoDroid] at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5974)
[MonoDroid] at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6158)
[MonoDroid] at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
[MonoDroid] at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
[MonoDroid] at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
[MonoDroid] at androidx.recyclerview.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:561)
[MonoDroid] at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
[MonoDroid] at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
[MonoDroid] at androidx.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
[MonoDroid] at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:4085)
[MonoDroid] at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3849)
[MonoDroid] at android.view.View.layout(View06-19 09:27:04.958 I/MonoDroid(18116): at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
[MonoDroid] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRo06-19 09:27:04.958 I/MonoDroid(18116): at crc643f46942d9dd1fff9.ItemsViewRenderer_3.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.ItemsViewRenderer_3.onLayout(ItemsViewRenderer_3.java:45)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout(Platform_DefaultRenderer.java:72)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout(Platform_DefaultRenderer.java:72)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:37)
[MonoDroid] at crc643f46942d9dd1fff9.PageRenderer.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.PageRenderer.onLayout(PageRenderer.java:72)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:37)
[MonoDroid] at crc643f46942d9dd1fff9.ShellPageContainer.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.ShellPageContainer.onLayout(ShellPageContainer.java:53)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
[MonoDroid] at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
[MonoDroid] at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
[MonoDroid] at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:918)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
[MonoDroid] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
[MonoDroid] at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native Method)
[MonoDroid] at crc643f46942d9dd1fff9.PlatformRenderer.onLayout(PlatformRenderer.java:63)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
[MonoDroid] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
[MonoDroid] at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[MonoDroid] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[MonoDroid] at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
[MonoDroid] at android.view.View.layout(View.java:20672)
[MonoDroid] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[MonoDroid] at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
[MonoDroid] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
[MonoDroid] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
[MonoDroid] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
[MonoDroid] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
[MonoDroid] at android.view.Choreographer.doCallbacks(Choreographer.java:761)
[MonoDroid] at android.view.Choreographer.doFrame(Choreographer.java:696)
[MonoDroid] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
[MonoDroid] at android.os.Handler.handleCallback(Handler.java:873)
[MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:99)
[MonoDroid] at android.os.Looper.loop(Looper.java:193)
[MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:6669)
[MonoDroid] at java.lang.reflect.Method.invoke(Native Method)
[MonoDroid] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
[MonoDroid]
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_throw'.
[Mono] Probing 'java_interop_jnienv_throw'.
[Mono] Found as 'java_interop_jnienv_throw'.
[.test.test_app] java_vm_ext.cc:545] JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethodA called with pending exception java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder{7860c34 position=3 id=-1, oldPos=2, pLpos:2 scrap [attachedScrap] tmpDetached not recyclable(1) no parent} crc643f46942d9dd1fff9.CollectionViewRenderer{70072e9 VFED..... ......ID 0,171-1080,1585 #a8}, adapter:crc643f46942d9dd1fff9.GroupableItemsViewAdapter_2@a7d829c, layout:androidx.recyclerview.widget.GridLayoutManager@fa62a46, context:android.view.ContextThemeWrapper@181df70
[.test.test_app] jav06-19 09:27:05.384 F/.test.test_app(18116): java_vm_ext.cc:545] (Throwable with no stack trace)
[.test.test_app] java_vm_ext.cc:545]
[.test.test_app] java_vm_ext.cc:545] in call to CallObjectMethodA
[.test.i06-19 09:27:05.384 F] java_vm_ext.cc:545] "main" prio=5 tid=1 Runnable
[.test.test_app] java_vm_ext.cc:545] | group="main" sCount=0 dsCount=0 flags=0 obj=0x74e99ee0 self=0xf05f4000
[.test.test_app] java_vm_ext.cc:545] | sysTid=18116 nice=-10 cgrp=default sched=0/0 handle=0xf51ba494
[.test.test_app] java_vm_ext.cc:545] | state=R schedstat=( 21627228939 6749814554 12612 ) utm=1990 stm=172 core=1 HZ=100
[.test.test_app] java_vm_ext.cc:545] | stack=0xff365000-0xff367000 stackSize=8MB
[.test.test_app] java_vm_ext.cc:545] | held mutexes= "mutator lock"(shared held)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6 void*, bool)+198)
[.test.test_app] java_vm_ext.cc:545] native: #01 pc 0051034e /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+382)
[.test.test_app] java_vm_ext.cc:545] native: #03 pc 0031a720 /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1088)
[.test.test_app] java_vm_ext.cc:545] native: #04 pc 0031ab91 /system/lib/libart.so (art::JavaVMExt::JniAbortV(char const*, char const*, char*)+113)
[.test.test_app] java_vm_ext.cc:545] native: #05 pc 000d5f77 /system/lib/libart.so (art::(anonymous namespace)::ScopedCheck::AbortF(char const*, ...)+71)
[.test.test_app] java_vm_ext.cc:545] native: #07 pc 000d3a5b /system/lib/libart.so (art::(anonymous namespace)::ScopedCheck::Check(art::ScopedObjectAccess&, bool, char const*, art::(anonymous namespace)::JniValueType*)+811)
[.test.test_app] java_vm_ext.cc:545] at and06-19 09:27:05.384 F/.test.test_app(18116): java_vm_ext.cc:545] native: #08 pc 000d9758 /system/lib/libart.so (art::(anonymous namespace)::CheckJNI::CheckCallArgs(art::ScopedObjectAccess&, art::(anonymous namespace)::ScopedCheck&, _JNIEnv*, _jobject*, _jclass*, _jmethodID*, art::InvokeType, art::(anonymous namespace)::VarArgs const*)+200)
[.test.test_app] java_vm_ext.cc:545] native: #10 pc 000c3f29 /system/lib/libart.so (art::(anonymous namespace)::CheckJNI::CallObjectMethodA(_JNIEnv*, _jobject*, _jmethodID*, jvalue*)+73)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.layoutVertical(06-19 09:27:05.384 F/.test.test_app(18116): java_vm_ext.cc:545] native: #11 pc 000100b8 /data/app/biz.test.test_appe-sqFo3WSkBLTuz8VxWGwung==/lib/x86/libmonodroid.so (java_interop_jnienv_call_object_method_a+56)
[.test.test_app] java_vm_ext.cc:545] native: #12 pc 0004c817 <anonymous:ccba4000> (???)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.ItemsViewRenderer_3.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.ItemsViewRenderer_3.onLayout(ItemsViewRenderer_3.java:45)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout(Platform_DefaultRenderer.java:72)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.view.Choreographer06-19 09:27:05.385 F/.test.test_app(18116): java_vm_ext.cc:545] at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:37)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:37)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.PageRenderer.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.PageRenderer.onLayout(PageRenderer.java:72)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:37)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.ShellPageContainer.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.ShellPageContainer.onLayout(ShellPageContainer.java:53)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
[.test.test_app] java_vm_ext.cc:545] at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
[.test.test_app] java_vm_ext.cc:545] at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
[.test.test_app] java_vm_ext.cc:545] at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:918)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native method)
[.test.test_app] java_vm_ext.cc:545] at crc643f46942d9dd1fff9.PlatformRenderer.onLayout(PlatformRenderer.java:63)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
[.test.test_app] java_vm_ext.cc:545] at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
[.test.test_app] java_vm_ext.cc:545] at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
[.test.test_app] java_vm_ext.cc:545] at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
[.test.test_app] java_vm_ext.cc:545] at android.view.View.layout(View.java:20672)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewGroup.layout(ViewGroup.java:6194)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
[.test.test_app] java_vm_ext.cc:545] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
[.test.test_app] java_vm_ext.cc:545] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
[.test.test_app] java_vm_ext.cc:545] at android.view.Choreographer.doCallbacks(Choreographer.java:761)
[.test.test_app] java_vm_ext.cc:545] at android.view.Choreographer.doFrame(Choreographer.java:696)
[.test.test_app] java_vm_ext.cc:545] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
[.test.test_app] java_vm_ext.cc:545] at android.os.Handler.handleCallback(Handler.java:873)
[.test.test_app] java_vm_ext.cc:545] at android.os.Handler.dispatchMessage(Handler.java:99)
[.test.test_app] java_vm_ext.cc:545] at android.os.Looper.loop(Looper.java:193)
[.test.test_app] java_vm_ext.cc:545] at android.app.ActivityThread.main(ActivityThread.java:6669)
[.test.test_app] java_vm_ext.cc:545] at java.lang.reflect.Method.invoke(Native method)
[.test.test_app] java_vm_ext.cc:545] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[.test.test_app] java_vm_ext.cc:545] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
[.test.test_app] java_vm_ext.cc:545]
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:
public ObservableCollection<object> YourItemSource { get; private set; }
[...]
ObservableCollection<object> tmpItemSource = new ObservableCollection<object>(YourItemSource);
YourItemSource.Clear();
[...]
foreach (object o in tmpItemSource)
YourItemSource.Add(o);
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 https://github.com/xamarin/Xamarin.Forms/issues/10735.
There are actually two different bugs demonstrated here:
We have a fix in progress (https://github.com/xamarin/Xamarin.Forms/pull/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 Java.Lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder
and I am already updating the ObservableCollection
on the main thread inside Device.BeginInvokeOnMainThread
so that fix is not relevant for me.
@inimirpaz I have the same crash as you, but using a temporary collection does not resolve it :( I want to update the collection items.
The below workaround solve my problem, maybe you want try:
(*using the example of inimirpaz)
public ObservableCollection
Instead of:
foreach (object o in tmpItemSource)
YourItemSource.Add(o);
I'm using:
YourItemSource = tmpItemSource;
I have the same problem. What's the solution?
@Cacuci The fix was done in this Pull Request: https://github.com/xamarin/Xamarin.Forms/commit/ab55162596774c18c1ed51f23c6727221505c1fa
And it is available in Xamarin.Forms v4.8.0-Pre2
Most helpful comment
@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.