在Mac OS版本低于10.12的情况下,NSOutlineView崩溃,因为默认情况下“ stronglyReferencesItems”设置为“ false” [英] NSOutlineView crash on Mac OS versions below 10.12 as 'stronglyReferencesItems' set to 'false' by default
问题描述
我的应用程序有一个大纲视图,可从服务器获取频繁的更新。每当我得到更新时,我都会重新加载大纲视图。我同时对轮廓进行了多种操作,例如在鼠标悬停,展开/折叠项目上显示一些按钮。对于这些操作,我使用 NSOutlineView.item(atRow:)
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:)
从大纲视图中获取项目随机场景我的应用在 NSOutlineView
内部调用的区域中被
delegate方法。我知道 EXC_BAD_ACCESS(SIGSEGV)
崩溃了低于10.12的OS版本上的NSTableView NSOutlineView
对于OS版本10.12的项目具有自己的保留和发布周期,因为 stronglyReferencesItems
设置为<$ c默认为$ c> true 。因此崩溃不会发生在10.12以上。
The issue is, at random scenarios my app is getting crashed with EXC_BAD_ACCESS (SIGSEGV)
in areas where NSOutlineView
internally calls NSTableView
delegate 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.
那么我该如何解决此问题?能否有人指导我如何手动保留和释放较低版本上传递给 NSOutlineView
的项目。
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.
简单地说,我需要启用 stronglyReferencesItems
的行为,将其设置为 true
在低于10.12的版本中。
Simply put I need to enable the behaviour of stronglyReferencesItems
set to true
in versions below 10.12.
注意:正如我上面所说,我使用 NSOutlineView
进行复杂的操作移动事件,展开/折叠(在某些情况下展开所有项目),使用服务器的频繁更新重新加载列表。因此在这里提到我的代码会很复杂。
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
推荐答案
在以下方法首次从表中引用项目时,可以将它们保留在数组中
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
这篇关于在Mac OS版本低于10.12的情况下,NSOutlineView崩溃,因为默认情况下“ stronglyReferencesItems”设置为“ false”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!