NSOutlineView crash on Mac OS versions below 10.12 as 'stronglyReferencesItems' set to 'false' by default

两盒软妹~` 提交于 2020-04-17 22:49:05

问题


My app has an outline view which get frequent updates from server. Whenever I get an update I reload outline view. I do multiple operation with outline at the same time like showing some buttons on mouse over, expand/collapse items. For these operations I get item from outline view with NSOutlineView.item(atRow:)

The issue is, at random scenarios my app is getting crashed with EXC_BAD_ACCESS (SIGSEGV) in areas where NSOutlineView internally calls NSTableViewdelegate methods on OS versions below 10.12. I know NSOutlineView has its own retain and release cycles for the items from OS version 10.12 as stronglyReferencesItems set to true by default. so the crashes not happening above 10.12.

So how can I resolve this issue? Can some one guide me how to do manual retain and release of items passed to NSOutlineView on lower versions.

Simply put I need to enable the behaviour of stronglyReferencesItems set to true in versions below 10.12.

Note: as I said above I do complex operations with NSOutlineView like move over events, expand/collapse (expanding all the items in some scenarios), reloading the list with frequent updates from server. So mentioning my code here would be complex.

Below is one of the crash logs for your reference:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib              0x000000010c5cec51 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 33
1   libswiftCore.dylib              0x000000010c5ab842 _swift_retain_n_(swift::HeapObject*, unsigned int) + 66
2   libswiftCore.dylib              0x000000010c5f7ac8 swift_bridgeObjectRetain_n + 104
3   com.prosoftnet.remotepcSuite    0x000000010bc8c626 RPCHostGroupTableCellView.setupView(group:) (in RemotePCSuite) (RPCHostGroupTableCellView.swift:0)
4   com.prosoftnet.remotepcSuite    0x000000010bd61198 RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (RPCHostListViewController.swift:579)
5   com.prosoftnet.remotepcSuite    0x000000010bd61a10 @objc RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (<compiler-generated>:0)
6   com.apple.AppKit                0x00007fff8f19e0d0 -[NSTableView(NSTableViewViewBased) makeViewForTableColumn:row:] + 76
7   com.apple.AppKit                0x00007fff8f19d541 -[NSTableRowData _addViewToRowView:atColumn:row:] + 300
8   com.apple.AppKit                0x00007fff8f19d27a -[NSTableRowData _addViewsToRowView:atRow:] + 184
9   com.apple.AppKit                0x00007fff8f19b9ad -[NSTableRowData _initializeRowView:atRow:] + 373
10  com.apple.AppKit                0x00007fff8f19aad2 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 396
11  com.apple.AppKit                0x00007fff8f23a9d1 -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 254
12  com.apple.AppKit                0x00007fff8f23a7a3 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 1856
13  com.apple.AppKit                0x00007fff8f239fc7 -[NSTableRowData updateVisibleRowViews] + 230
14  com.apple.AppKit                0x00007fff8f23fe82 -[NSTableView viewWillDraw] + 178
15  com.apple.AppKit                0x00007fff8f2bd83f -[NSOutlineView viewWillDraw] + 169
16  com.apple.AppKit                0x00007fff8f0e6fa1 -[NSView(NSInternal) _sendViewWillDrawAndRecurse:] + 535
17  com.apple.AppKit                0x00007fff8f058ae1 -[NSView(NSLayerKitGlue) _layoutSublayersOfLayer:] + 142
18  com.apple.QuartzCore            0x00007fff8dd79404 -[CALayer layoutSublayers] + 219
19  com.apple.AppKit                0x00007fff8f058a3c _NSBackingLayerLayoutSublayers + 158
20  com.apple.QuartzCore            0x00007fff8dd78fe8 CA::Layer::layout_if_needed(CA::Transaction*) + 366
21  com.apple.QuartzCore            0x00007fff8dd78e66 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
22  com.apple.QuartzCore            0x00007fff8dd78602 CA::Context::commit_transaction(CA::Transaction*) + 242
23  com.apple.QuartzCore            0x00007fff8dd7839e CA::Transaction::commit() + 390
24  com.apple.QuartzCore            0x00007fff8dd86f09 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 71
25  com.apple.CoreFoundation        0x00007fff99bdaf47 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
26  com.apple.CoreFoundation        0x00007fff99bdaea0 __CFRunLoopDoObservers + 368
27  com.apple.CoreFoundation        0x00007fff99bcca18 CFRunLoopRunSpecific + 328
28  com.apple.HIToolbox             0x00007fff8eb4256f RunCurrentEventLoopInMode + 235
29  com.apple.HIToolbox             0x00007fff8eb422ea ReceiveNextEventCommon + 431
30  com.apple.HIToolbox             0x00007fff8eb4212b _BlockUntilNextEventMatchingListInModeWithFilter + 71
31  com.apple.AppKit                0x00007fff8f08a8ab _DPSNextEvent + 978
32  com.apple.AppKit                0x00007fff8f089e58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
33  com.apple.AppKit                0x00007fff8f07faf3 -[NSApplication run] + 594
34  com.apple.AppKit                0x00007fff8effc244 NSApplicationMain + 1832
35  com.prosoftnet.remotepcSuite    0x000000010bc519a9 main (in RemotePCSuite) (AppDelegate.swift:12)
36  libdyld.dylib                   0x00007fff8e4b95c9 start + 1

回答1:


You could retain the items in an array when they get first referenced from the table in the below method

var items = [ItemType]()
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) 
{
    let item = getItem()
    items.append(item)
    return item
}

Your gonna run into trouble with not know when you can release them though. Youll have to manually handle that logic



来源:https://stackoverflow.com/questions/60549193/nsoutlineview-crash-on-mac-os-versions-below-10-12-as-stronglyreferencesitems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!