0

I'm facing a rather odd problem. With subclassing some NSViews, NSTableView and NSScrollView to be specific.

Situation: I'm working on a quite old (ca. 7 year) project for macOS. The codebase is about 50% objc and 50% swift 3.2 and uses XIB files for the individual views. The application runs smoothly on 10.10 - 10.12 but it crashes on 10.13 pretty much instantly.

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.

Problem: The view of that controller has a NSTableview, which I subclassed and assigned the class in the interface builder to the table object. 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.

I tried creating a new app utilising xib with the view controller and a subclassed NSTableView and it works just fine!

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.

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.

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).

I appreciate every help or input you can give me. Thank you

Laniakaeus
  • 11
  • 2
  • If a new project with a subclassed NSTableView doesn't crash, then I'm not sure how we can diagnose it from here. Take a copy of the project and keep removing parts until it works? – Ssswift Nov 06 '17 at 17:03
  • Which window, do you think, is returned from `windowForSheet`? – Willeke Nov 06 '17 at 20:58
  • @Willeke As it is a document based app, its the main (there is usually only 1) window (NSWindow). – Laniakaeus Nov 07 '17 at 11:13
  • @Ssswift Sadly I can't provide the original project. My current approach is to migrate a xib file to a storyboard and see if the subclass causes a problem there as well. – Laniakaeus Nov 07 '17 at 11:17
  • Do you want to assign the contentViewController.view to the main window or to the sheet? – Willeke Nov 07 '17 at 14:41
  • @Willeke As I mentioned in my description, accessing or setting the view is not the problem but more the first visible point where the symptom of the problem shows up. If the view I'm assigning to the content of the window does not contain a tableview subclass or no table at all, everything works fine. – Laniakaeus Nov 07 '17 at 15:37
  • Similar problem: [Xib loading crashes when it contains NSSCrollView](https://stackoverflow.com/questions/47198173/xib-loading-crashes-when-it-contains-nsscrollview) – Willeke Nov 09 '17 at 16:22

1 Answers1

0

Try to update old frameworks. I had the same problem with Sparkle. Updating from 1.8.0 to 1.18.1 have solved two similar bugs.

(ca. 7 year) project for macOS.

It's sad, but haven't found the exact commit in Sparkle that has fixed the crash. I think it is between versions 1.8.0 and 1.9.0. Please let me know if you find the exact line of code caused the crash.

Nuzhdin Vladimir
  • 1,714
  • 18
  • 36