ReactiveCocoa: Crash during runloop's autorelease pool drain on macOS 10.15 Catalina
Experiencing a naughty crash with buttons and all inheriting classes inside NSStackView with enabled Detaches Hidden Views when the window gets closed and deallocated in the latest Catalina build:
2019-10-06 15:04:27.548688+0100 App[4474:58829] [general] Caught exception during runloop's autorelease pool drain of client objects NSRangeException: Cannot remove an observer <NSStackView 0x10461aca0> for the key path "hidden" from <NSButton 0x10461c7f0> because it is not registered as an observer. userInfo: (null)
2019-10-06 15:04:27.550252+0100 App[4474:58829] [General] An uncaught exception was raised
2019-10-06 15:04:27.550313+0100 App[4474:58829] [General] Cannot remove an observer <NSStackView 0x10461aca0> for the key path "hidden" from <NSButton 0x10461c7f0> because it is not registered as an observer.
0 CoreFoundation 0x00007fff36166d63 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6bf56bd4 objc_exception_throw + 48
2 Foundation 0x00007fff387a7395 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 578
3 Foundation 0x00007fff387a7106 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 74
4 Foundation 0x00007fff387bf963 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 190
5 AppKit 0x00007fff334e0cc9 -[NSStackView dealloc] + 233
6 CoreFoundation 0x00007fff360c5176 -[__NSArrayI dealloc] + 73
7 libobjc.A.dylib 0x00007fff6bf6653a _ZN19AutoreleasePoolPage12releaseUntilEPP11objc_object + 134
8 libobjc.A.dylib 0x00007fff6bf4cc70 objc_autoreleasePoolPop + 175
9 CoreFoundation 0x00007fff3608767e _CFAutoreleasePoolPop + 22
10 CoreFoundation 0x00007fff360b59fc __CFRunLoopRun + 2404
11 CoreFoundation 0x00007fff360b4e13 CFRunLoopRunSpecific + 499
12 HIToolbox 0x00007fff34c41b2d RunCurrentEventLoopInMode + 292
13 HIToolbox 0x00007fff34c4186d ReceiveNextEventCommon + 600
14 HIToolbox 0x00007fff34c415f7 _BlockUntilNextEventMatchingListInModeWithFilter + 64
15 AppKit 0x00007fff332eaac4 _DPSNextEvent + 990
16 AppKit 0x00007fff332e9834 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
17 AppKit 0x00007fff332e3fd4 -[NSApplication run] + 658
18 AppKit 0x00007fff332d5e7d NSApplicationMain + 777
As far as I can tell this has been happening since Catalina Beta was released and still occurs on the latest GM seed, which is worrying… Builds produced with the latest stable Xcode and Xcode 11.2 Beta suffer from the same problem. Everything pre-Catalina works 100% fine.
All of the above narrows down to ReactiveCocoa bindings. Removing the following observeValues line fixes the issue:
override func viewDidLoad() {
self.launchOnStartupCheckbox.reactive.boolValues.observeValues({ Swift.print($0) })
}
It seems like there’s something wrong with ObjC swizzling that ReactiveCocoa does behind the scenes? It also looks there’re some observer-related issues, is this something related or already known? Otherwise happy to try isolating the issue into a sample project, but there’s really not much details besides that: NSStackView with enabled Detaches Hidden Views + NSButton + reactive observer on button’s IBOutlet = 💥 on window deallocation!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 22 (22 by maintainers)
@ianbytchek This looks like isa-swizzling RAC did is intefering with some assumptions made by NSStackView or KVO internals in Catalina. Have to look deeper into how this can be resolved.
Another interesting fact. If I understand correctly ReactiveCocoa uses different swizzling for different things. So, depending on that and on the observation order it shows different results. There are cases when turning off hidden view detaching doesn’t even work.
Doesn’t seem to be happening any longer on latest Catalina 10.15.4.I encountered a few other notorious AppKit crashes on 10.15, so this probably was one of these internal oversights. Feel free to close.