Bug 60813 - [iOS] ListView throws Exception on ObservableCollection.Add/Remove
Summary: [iOS] ListView throws Exception on ObservableCollection.Add/Remove
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.5.0
Hardware: PC Windows
: Normal critical
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-22 14:29 UTC by Matthias
Modified: 2017-12-19 08:16 UTC (History)
3 users (show)

Tags: listview, nre, ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro (324.30 KB, application/x-zip-compressed)
2017-11-22 14:29 UTC, Matthias
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Matthias 2017-11-22 14:29:23 UTC
Created attachment 25801 [details]
repro

# Summary

When a ListView is in a Page that is not activated (Tab of TabbedPage) and its ItemsSource is updated it throws an error.

# Reproduction

The attached sample reproduces the error. When the action "Add 1/2/3" is clicked, an item is added to one of the three lists - inside three tabs - respectively. When "Add 2" or "Add 3" is clicked *before* navigating to either page, the App crashes.

# Stack trace

FormsIOSListViewCrash.iOS(12969,0x11a6593c0) malloc: *** error for object 0x60000143a2c0: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
2017-11-22 15:12:28.021 FormsIOSListViewCrash.iOS[12969:156528] critical: Stacktrace:

2017-11-22 15:12:28.023 FormsIOSListViewCrash.iOS[12969:156528] critical:   at <unknown> <0xffffffff>
2017-11-22 15:12:28.023 FormsIOSListViewCrash.iOS[12969:156528] critical:   at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) [0x0000a] in <f5f7bf9082f2423098c34fc985600d02>:0
2017-11-22 15:12:28.024 FormsIOSListViewCrash.iOS[12969:156528] critical:   at UIKit.UITableView.EndUpdates () [0x00010] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/build/ios/native/UIKit/UITableView.g.cs:294
2017-11-22 15:12:28.024 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs,int,bool) [0x00106] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:533
2017-11-22 15:12:28.024 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamari
n.Forms.Platform.iOS.ListViewRenderer.OnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x00000] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:298
2017-11-22 15:12:28.025 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.Internals.TemplatedItemsList`2<TView_REF, TItem_REF>.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x0000a] in D:\agent\_work\2\s\Xamarin.Forms.Core\TemplatedItemsList.cs:771
2017-11-22 15:12:28.025 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.Internals.TemplatedItemsList`2<TView_REF, TItem_REF>.OnProxyCollectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs,bool) [0x0001a] in D:\agent\_work\2\s\Xamarin.Forms.Core\TemplatedItemsList.cs:981
2017-11-22 15:12:28.025 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.Internals.TemplatedItemsList`2<TView_REF, TItem_REF>.OnProxyCollectionCh
anged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x00000] in D:\agent\_work\2\s\Xamarin.Forms.Core\TemplatedItemsList.cs:968
2017-11-22 15:12:28.025 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x0000a] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:233
2017-11-22 15:12:28.026 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.ListProxy/<>c__DisplayClass33_0.<OnCollectionChanged>b__0 () [0x00018] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:206
2017-11-22 15:12:28.026 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.ListProxy.OnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x000a0] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:225
2017-11-22 15:12:28.026 FormsIOSListViewCrash.iOS[12969:156528] critical:   at Xamarin.Forms.ListProxy/WeakNotifyProxy.OnColl
ectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x00031] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:394
2017-11-22 15:12:28.026 FormsIOSListViewCrash.iOS[12969:156528] critical:   at System.Collections.ObjectModel.ObservableCollection`1<T_REF>.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs) [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288
2017-11-22 15:12:28.026 FormsIOSListViewCrash.iOS[12969:156528] critical:   at System.Collections.ObjectModel.ObservableCollection`1<T_REF>.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction,object,int) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351
2017-11-22 15:12:28.026 FormsIOSListViewCra
sh.iOS[12969:156528] critical:   at System.Collections.ObjectModel.ObservableCollection`1<T_REF>.InsertItem (int,T_REF) [0x00024] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219
2017-11-22 15:12:28.027 FormsIOSListViewCrash.iOS[12969:156528] critical:   at System.Collections.ObjectModel.Collection`1<T_REF>.Add (T_REF) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:67
2017-11-22 15:12:28.027 FormsIOSListViewCrash.iOS[12969:156528] critical:   at FormsIOSListViewCrash.MainViewModel.<.ctor>b__0_1 () [0x00000] in C:\Source\Local\FormsIOSListViewCrash\FormsIOSListViewCrash\FormsIOSListViewCrash\App.xaml.cs:54

# Versions

2.4.280 BAD
2.5.0.91635 BAD
Comment 1 Matthias 2017-11-22 16:30:45 UTC
Just reproduces this in current X.F master and got the following:

Unhandled Exception:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
Native stack trace:
	0   CoreFoundation                      0x000000011be3b1ab __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000011ca94f41 objc_exception_throw + 48
	2   CoreFoundation                      0x000000011be40372 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x0000000111a52089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
	4   UIKit                               0x000000010ed7c6b2 -[UITableView _endCellAnimationsWithContext:] + 19406
	5   UIKit                               0x000000010ed96d25 -[UITableView endUpdates] + 75
	6   XamarinFormsControlGalleryiOS       0x000000010db8e759 xamarin_dyn_objc_msgSend + 217
	7   ???                                 0x000000013c19bd22 0x0 + 5303287074
 occurred



I will publish my branch and link it here.
Comment 2 Matthias 2017-11-22 16:43:22 UTC
Here is the branch:

https://github.com/bruzkovsky/Xamarin.Forms/tree/fix-bugzilla60813

Note: You have to use Xamarin.Forms.iOS.sln
Comment 3 Paul DiPietro [MSFT] 2017-11-28 02:35:16 UTC
Thanks for the repro -- might be related or the same as 60734, but having a runnable project here makes this easier to confirm crashing.
Comment 4 Matthias 2017-12-12 09:56:06 UTC
This is now tracked on GitHub: https://github.com/xamarin/Xamarin.Forms/issues/1342