崩溃:[NSCollectionViewData layoutAttributesForItemAtIndexPath]

时间:2018-11-22 14:48:15

标签: swift macos macos-mojave

试图了解这场崩溃已有几天了。

对于某些用户(随机地,操作系统10.14 / 10.14.1),应用在首次加载时崩溃。

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

从外观上看,似乎该应用尚未加载事件。

我什至设法找到了一个存在相同问题的人,在他的计算机上安装了Xcode并在本地运行相同版本,一切正常! 不仅如此,但在我下载之后,下载的应用程序也能正常工作!这太奇怪了,我真的不知道发生了什么。 越来越多的用户对此感到担忧,但并非所有人。

2 个答案:

答案 0 :(得分:6)

一开始我遇到了随机崩溃的问题。

可能的原因:

  1. 具有不同大小的CollectionViewItem

  2. viewFor()甚至在视图加载之前调用(在切换,更改或编辑视图时发生)

  3. 编辑一个影响另一个收藏夹视图项的收藏夹视图项的大小(如果删除了前者,则可能)

我通过添加if条件来检查集合视图是否为nil来修复它。另外,通过在更改视图时检查数据源numberOfItems是否一致。

答案 1 :(得分:0)

就我而言,我没有使用NSCollectionView.elementKindSectionHeader。相反,我使用了已定义的自定义字符串。