简体   繁体   English

通过子类化NSTableView或NSScrollView引起的macOS 10.13 EXEC_BAD_ACCESS

[英]macOS 10.13 EXEC_BAD_ACCESS caused by subclassing NSTableView or NSScrollView

I'm facing a rather odd problem. 我面临一个相当奇怪的问题。 With subclassing some NSViews, NSTableView and NSScrollView to be specific. 通过对某些NSViews进行子类化,可以使NSTableView和NSScrollView更加具体。

Situation : I'm working on a quite old (ca. 7 year) project for macOS. 情况 :我正在为macOS开发一个相当老的项目(大约7年)。 The codebase is about 50% objc and 50% swift 3.2 and uses XIB files for the individual views. 该代码库的objc约为50%,而swift 3.2约为50%,并且对各个视图使用XIB文件。 The application runs smoothly on 10.10 - 10.12 but it crashes on 10.13 pretty much instantly. 该应用程序可在10.10-10.12上顺利运行,但几乎立即会在10.13上崩溃。

The backtrace shows the following: 回溯显示以下内容:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00007fff50490b05 Foundation`_NSKVONotifyingCreateInfoWithOriginalClass + 177
frame #1: 0x00007fff50490a35 Foundation`_NSKeyValueContainerClassGetNotifyingInfo + 59
frame #2: 0x00007fff504908c4 Foundation`-[NSKeyValueUnnestedProperty _isaForAutonotifying] + 75
frame #3: 0x00007fff5049075f Foundation`-[NSKeyValueUnnestedProperty isaForAutonotifying] + 75
frame #4: 0x00007fff5048f9fb Foundation`-[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:] + 490
frame #5: 0x00007fff5048e7c9 Foundation`-[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 103
frame #6: 0x00007fff504da865 Foundation`-[NSKeyValueNestedProperty object:withObservance:didChangeValueForKeyOrKeys:recurse:forwardingValues:] + 411
frame #7: 0x00007fff504af6d8 Foundation`NSKeyValueDidChange + 179
frame #8: 0x00007fff505eb370 Foundation`NSKeyValueDidChangeWithPerThreadPendingNotifications + 132
frame #9: 0x00007fff4c2ac3a0 AppKit`-[NSView didChangeValueForKey:] + 93
frame #10: 0x00007fff504aff4d Foundation`NSKeyValueNotifyObserver + 350
frame #11: 0x00007fff504af800 Foundation`NSKeyValueDidChange + 475
frame #12: 0x00007fff505eb370 Foundation`NSKeyValueDidChangeWithPerThreadPendingNotifications + 132
frame #13: 0x00007fff4c2ac3a0 AppKit`-[NSView didChangeValueForKey:] + 93
frame #14: 0x00007fff4bbf6877 AppKit`-[NSScrollView _makeUnderTitlebarView] + 165
frame #15: 0x00007fff4b9e9eff AppKit`-[NSScrollView _updateStateOfUnderTitlebarView] + 327
frame #16: 0x00007fff4bae5ef1 AppKit`-[NSScrollView viewDidMoveToWindow] + 113
frame #17: 0x00007fff4b9e82b2 AppKit`-[NSView _setWindow:] + 2867
frame #18: 0x00007fff4b9efe9d AppKit`-[NSScrollView _setWindow:] + 500
frame #19: 0x00007fff4e3ef79f CoreFoundation`-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 239
frame #20: 0x00007fff4c2acfed AppKit`__21-[NSView _setWindow:]_block_invoke.604 + 141
frame #21: 0x00007fff504c9b4a Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
frame #22: 0x00007fff4b9e602d AppKit`-[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 70
frame #23: 0x00007fff4b9e8203 AppKit`-[NSView _setWindow:] + 2692
frame #24: 0x00007fff4b9e52d5 AppKit`-[NSView addSubview:] + 257
frame #25: 0x00007fff4ba1e228 AppKit`-[NSFrameView addSubview:] + 44
frame #26: 0x00007fff4ba1e1ed AppKit`-[NSThemeFrame addSubview:] + 381
frame #27: 0x00007fff4ba1df1a AppKit`-[NSView addSubview:positioned:relativeTo:] + 214
frame #28: 0x00007fff4c2593bd AppKit`-[NSThemeFrame addSubview:positioned:relativeTo:] + 42
frame #29: 0x00007fff4ba1de37 AppKit`-[NSThemeFrame _addKnownSubview:positioned:relativeTo:] + 38
frame #30: 0x00007fff4ba43853 AppKit`-[NSWindow setContentView:] + 382
frame #31: 0x000000010007e8da MyApp`-[Document someContentViewItemSelected:](self=0x000060403b97eef0, _cmd="someContentViewItemSelected:", sender=0x0000604043fb0f60) at Document.m:230

The backtrace is not very helpful (but maybe I'm missing something), but the error occurs when the view of a new ViewController gets assigned to the window sheet's content view self.windowForSheet.contentView = contentViewController.view . 回溯不是很有用(但是我可能缺少一些东西),但是当将新ViewController的视图分配给窗口工作表的内容视图self.windowForSheet.contentView = contentViewController.view时,就会发生错误。

Problem : The view of that controller has a NSTableview, which I subclassed and assigned the class in the interface builder to the table object. 问题 :该控制器的视图具有一个NSTableview,我将其子类化,并将接口构建器中的类分配给表对象。 If I remove this subclass, everything works fine. 如果删除此子类,则一切正常。

What I tried : 我试过了

I tried to reproduce the problem with completely empty subclasses written in objc and swift and with both, the problem occurs and the app crashes with the exact same backtrace. 我试图用objc和swift编写的完全为空的子类重现该问题,并且同时发生了问题和应用程序崩溃,并产生了完全相同的回溯。

I tried creating a new app utilising xib with the view controller and a subclassed NSTableView and it works just fine! 我尝试使用带有视图控制器和子类NSTableView的xib创建一个新应用,它工作得很好!

I tried compiling the app with Xcode 8.3.3 (on 10.12 & 10.13)and 9.1 (on10.13) and the resulting apps show the same behaviour, working fine on 10.12, 10.11 but crashes on 10.13. 我尝试使用Xcode 8.3.3(在10.12和10.13上)和9.1(在10.13上)编译应用程序,结果应用程序显示出相同的行为,在10.12、10.11上可以正常工作,但在10.13上崩溃。

I assume it all has to do with it being a very old project with mixed languages and outdated xib files, but I can't point my fingers at specifics. 我认为这与它是一个非常老的项目有关,它具有混合语言和过时的xib文件,但我无法指责具体细节。

Question: Do you guys know what this problem could be? 问题:你们知道这个问题可能是什么吗? Have had problems with subclassing NSTableView or NSScrollView (NSTableViewCell subclasses work just fine by the way). 在子类化NSTableView或NSScrollView时遇到了问题(顺便说一句,NSTableViewCell子类可以正常工作)。

I appreciate every help or input you can give me. 我感谢您能给我的任何帮助或意见。 Thank you 谢谢

Try to update old frameworks. 尝试更新旧框架。 I had the same problem with Sparkle . 我在Sparkle遇到了同样的问题 Updating from 1.8.0 to 1.18.1 have solved two similar bugs. 从1.8.0升级到1.18.1已解决了两个类似的错误。

(ca. 7 year) project for macOS. (约7年)macOS项目。

It's sad, but haven't found the exact commit in Sparkle that has fixed the crash. 很遗憾,但是在Sparkle中没有找到修复崩溃的确切提交。 I think it is between versions 1.8.0 and 1.9.0. 我认为它介于版本1.8.0和1.9.0之间。 Please let me know if you find the exact line of code caused the crash. 如果您找到导致崩溃的确切代码行,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM