gpt4 book ai didi

swift - NSOutlineView 在低于 10.12 的 Mac OS 版本上崩溃,因为 'stronglyReferencesItems' 默认设置为 'false'

转载 作者:行者123 更新时间:2023-12-03 17:46:06 25 4
gpt4 key购买 nike

我的应用程序有一个大纲 View ,可以从服务器频繁更新。每当我收到更新时,我都会重新加载大纲 View 。我同时对轮廓进行多项操作,例如在鼠标悬停时显示一些按钮、展开/折叠项目。对于这些操作,我使用 NSOutlineView.item(atRow:)

从大纲 View 中获取项目

问题是,在随机情况下,我的应用程序在 NSOutlineView 内部调用 NSTableView 委托(delegate)方法的区域中因 EXC_BAD_ACCESS (SIGSEGV) 崩溃在低于 10.12 的操作系统版本上。我知道 NSOutlineView 对于操作系统版本 10.12 中的项目有自己的保留和释放周期,因为 stronglyReferencesItems 默认设置为 true。所以崩溃不会发生在 10.12 以上。

那么我该如何解决这个问题呢?有人可以指导我如何在较低版本上手动保留和释放传递给 NSOutlineView 的项目吗?

简单地说,我需要在 10.12 以下的版本中启用将 stronglyReferencesItems 设置为 true 的行为。

注意:正如我上面所说,我使用 NSOutlineView 执行复杂的操作,例如移动事件、展开/折叠(在某些情况下展开所有项目)、通过服务器的频繁更新重新加载列表。因此,在这里提及我的代码会很复杂。

以下是崩溃日志之一供您引用:

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

最佳答案

当第一次从下面的方法中的表中引用这些项目时,您可以将它们保留在数组中

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

你会遇到麻烦,不知道什么时候可以释放它们。您必须手动处理该逻辑

关于swift - NSOutlineView 在低于 10.12 的 Mac OS 版本上崩溃,因为 'stronglyReferencesItems' 默认设置为 'false',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60549193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com