Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash: [NSCollectionViewData layoutAttributesForItemAtIndexPath]

Trying to understand this crash for days now.

For some users (Randomly, operation systems 10.14/10.14.1) app crashes on the first load.

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
-[NSCollectionViewData layoutAttributesForItemAtIndexPath:]

Crashed: com.apple.main-thread
0  UIFoundation                   0x7fff7ac71c6a -[NSCollectionViewData layoutAttributesForItemAtIndexPath:] + 72
1  UIFoundation                   0x7fff7ac3cb52 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 7748
2  UIFoundation                   0x7fff7ac358a9 -[_NSCollectionViewCore _layoutItems] + 298
3  AppKit                         0x7fff5019dbc2 -[NSCollectionView layout] + 360
4  AppKit                         0x7fff5002e755 _NSViewLayout + 587
5  AppKit                         0x7fff5002e0fc -[NSView _layoutSubtreeWithOldSize:] + 446
6  AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
7  AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
8  AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
9  AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
10 AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
11 AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
12 AppKit                         0x7fff5002e375 -[NSView _layoutSubtreeWithOldSize:] + 1079
13 AppKit                         0x7fff5002bb96 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1358
14 AppKit                         0x7fff5002b332 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
15 AppKit                         0x7fff5003cfee -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 263
16 AppKit                         0x7fff50041469 -[NSWindow displayIfNeeded] + 180
17 AppKit                         0x7fff5004130f __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 722
18 AppKit                         0x7fff5003c41a NSDisplayCycleObserverInvoke + 170
19 AppKit                         0x7fff5003bf8f NSDisplayCycleFlush + 1073
20 QuartzCore                     0x7fff5d9621d3 CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
21 QuartzCore                     0x7fff5d961b9a CA::Transaction::commit() + 186
22 AppKit                         0x7fff5003b8f5 __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
23 CoreFoundation                 0x7fff52a3f95d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation                 0x7fff52a3f892 __CFRunLoopDoObservers + 452
25 CoreFoundation                 0x7fff529e13c5 __CFRunLoopRun + 1166
26 CoreFoundation                 0x7fff529e0ce4 CFRunLoopRunSpecific + 463
27 HIToolbox                      0x7fff51c7a895 RunCurrentEventLoopInMode + 293
28 HIToolbox                      0x7fff51c7a5cb ReceiveNextEventCommon + 618
29 HIToolbox                      0x7fff51c7a348 _BlockUntilNextEventMatchingListInModeWithFilter + 64
30 AppKit                         0x7fff4ff3795b _DPSNextEvent + 997
31 AppKit                         0x7fff4ff366fa -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
32 AppKit                         0x7fff4ff3075d -[NSApplication run] + 699
33 AppKit                         0x7fff4ff1fe97 NSApplicationMain + 780
34 TodoDock                       0x105173a99 main (AppDelegate.swift:18)
35 libdyld.dylib                  0x7fff7fa7a085 start + 1

By the looks of it, it seems the app didn't event load yet.

I even managed to get to a guy that had the same issue, installed Xcode on his machine and run the same version locally, and everything worked! Not only that but after I did, the downloaded app worked too! This is so strange, I really do not have a clue what is going on. And more users are expirancing this, but not all of them.

like image 895
MCMatan Avatar asked Nov 22 '18 14:11

MCMatan


1 Answers

I had the same problem of random crashes at the start.

Possible reasons:

  1. CollectionViewItem with different size

  2. viewFor() called before the view is even loaded (Happens when switching or changing or editing the views)

  3. Editing the size of one collection view item affecting the other collection view item(possible if the former is removed)

I fixed it by adding if condition to check whether the collection view is nil or not. Also by checking whether the datasource numberOfItems is consistent when changing the views.

like image 71
mouseymaniac Avatar answered Sep 24 '22 13:09

mouseymaniac