Assertion failed in Separated-style NSSegmentedControl when window moved from a Retina to non-Retina screen

Originator:zacharias.pasternack
Number:rdar://23290438 Date Originated:10/27/15
Status:Open Resolved:No
Product:AppKit Product Version:
Classification:Crash Reproducible:Always
 
Summary:
When a Separated-style NSSegmentedControl is in an auto-layout window, and that window is moved from a Retina to a non-Retina screen (or vice-versa), an assertion is failed in -[NSSegmentedControl ns_widgetType]. 

Output from the debugger is as follows:
2015-10-27 22:02:25.889 SegmentedControlTest[14965:910170] *** Assertion failure in -[NSSegmentedControl ns_widgetType], /Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1404.13/Layout.subproj/NSUserInterfaceTheme.m:413
2015-10-27 22:02:25.889 SegmentedControlTest[14965:910170] What kind of segmented control are we!
2015-10-27 22:02:25.895 SegmentedControlTest[14965:910170] (
	0   CoreFoundation                      0x00007fff995ece32 __exceptionPreprocess + 178
	1   libobjc.A.dylib                     0x00007fff963e0dd4 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff995f1b0a +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x00007fff94c1de16 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
	4   AppKit                              0x00007fff8fbd51fd -[NSSegmentedControl(NSIBSegmentedControlIntegration) ns_widgetType] + 219
	5   AppKit                              0x00007fff8faa71a4 -[NSAquaUserInterfaceTheme _ruleForView:comparedToView:withEdge:] + 64
	6   AppKit                              0x00007fff8faa70ca -[NSAquaUserInterfaceTheme resolvedValue:forSymbolicConstant:inConstraint:containerView:] + 521
	7   AppKit                              0x00007fff8faa6d57 -[NSLayoutConstraint(NSSymbolicConstantResolution) defaultResolvedValue:forSymbolicConstant:error:] + 89
	8   Foundation                          0x00007fff94b8f5f1 -[NSLayoutConstraint _effectiveConstant:error:] + 105
	9   Foundation                          0x00007fff94b8f4f3 -[NSLayoutConstraint constant] + 52
	10  Foundation                          0x00007fff94b8e910 -[NSLayoutConstraint _lowerIntoExpression:reportingConstantIsRounded:] + 200
	11  Foundation                          0x00007fff94b95c31 -[NSLayoutConstraint _containerGeometryDidChange] + 88
	12  AppKit                              0x00007fff8f8aac31 _NSViewEnumerateConstraints + 253
	13  AppKit                              0x00007fff8f929d06 __52-[NSView(NSConstraintBasedLayout) _setLayoutEngine:]_block_invoke_2 + 323
	14  Foundation                          0x00007fff94b8e502 -[NSISEngine withBehaviors:performModifications:] + 155
	15  AppKit                              0x00007fff8f8959fe -[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 70
	16  AppKit                              0x00007fff8f929ba6 __52-[NSView(NSConstraintBasedLayout) _setLayoutEngine:]_block_invoke + 485
	17  AppKit                              0x00007fff8f8a0762 -[NSView(NSConstraintBasedLayout) _setLayoutEngine:] + 233
	18  AppKit                              0x00007fff8f929c9b __52-[NSView(NSConstraintBasedLayout) _setLayoutEngine:]_block_invoke_2 + 216
	19  Foundation                          0x00007fff94b8e502 -[NSISEngine withBehaviors:performModifications:] + 155
	20  AppKit                              0x00007fff8f8959fe -[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 70
	21  AppKit                              0x00007fff8f929ba6 __52-[NSView(NSConstraintBasedLayout) _setLayoutEngine:]_block_invoke + 485
	22  AppKit                              0x00007fff8f8a0762 -[NSView(NSConstraintBasedLayout) _setLayoutEngine:] + 233
	23  AppKit                              0x00007fff8f9299a6 make_and_host_engine + 335
	24  AppKit                              0x00007fff90234c3d -[NSView(NSConstraintBasedLayout) _rebuildLayoutFromScratch] + 135
	25  AppKit                              0x00007fff900892e4 -[NSWindow _setWindowResolution:displayIfChanged:] + 256
	26  AppKit                              0x00007fff8fc2af26 -[NSWindow _updateInheritedBackingScaleFactorAndDisplayIfChanged:] + 114
	27  AppKit                              0x00007fff8fa70f58 __67-[NSWindow _updateSettingsSendingScreenChangeNotificationIfNeeded:]_block_invoke + 165
	28  AppKit                              0x00007fff8f9f1f05 NSPerformVisuallyAtomicChange + 147
	29  AppKit                              0x00007fff8f972028 -[NSWindow _updateSettingsSendingScreenChangeNotificationIfNeeded:] + 366
	30  AppKit                              0x00007fff8fc8bc11 -[NSWindow _screenChanged:] + 58
	31  AppKit                              0x00007fff8fc8bb92 -[NSWindow _displayChangedSoAdjustWindows:] + 152
	32  AppKit                              0x00007fff8fa4bfc0 __44-[NSApplication makeWindowsPerform:inOrder:]_block_invoke + 27
	33  AppKit                              0x00007fff8fa4bf7c __48-[NSApplication _findWindowInOrder:passingTest:]_block_invoke + 26
	34  AppKit                              0x00007fff8f8b40f1 -[NSApplication _enumerateWindowsInOrder:usingBlock:] + 545
	35  AppKit                              0x00007fff8f8b3e91 -[NSApplication _findWindowInOrder:passingTest:] + 165
	36  AppKit                              0x00007fff8f8b3dda -[NSApplication makeWindowsPerform:inOrder:] + 252
	37  AppKit                              0x00007fff8fc8b92a -[NSApplication _reactToScreenInvalidationImmediately:] + 67
	38  AppKit                              0x00007fff8fc8b8b7 __44-[NSApplication _reactToScreenInvalidation:]_block_invoke + 59
	39  CoreFoundation                      0x00007fff995824dc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	40  CoreFoundation                      0x00007fff99561df5 __CFRunLoopDoBlocks + 341
	41  CoreFoundation                      0x00007fff99561b5b __CFRunLoopRun + 2347
	42  CoreFoundation                      0x00007fff99560fc8 CFRunLoopRunSpecific + 296
	43  HIToolbox                           0x00007fff92ff5d55 RunCurrentEventLoopInMode + 235
	44  HIToolbox                           0x00007fff92ff5b8f ReceiveNextEventCommon + 432
	45  HIToolbox                           0x00007fff92ff59cf _BlockUntilNextEventMatchingListInModeWithFilter + 71
	46  AppKit                              0x00007fff8f8b7d96 _DPSNextEvent + 1067
	47  AppKit                              0x00007fff8f8b71c5 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
	48  AppKit                              0x00007fff8f8abd28 -[NSApplication run] + 682
	49  AppKit                              0x00007fff8f874fbe NSApplicationMain + 1176
	50  SegmentedControlTest                0x0000000100000f52 main + 34
	51  libdyld.dylib                       0x00007fff8ed3d5ad start + 1
)

Steps to Reproduce:
Note: To reproduce this, you will need either a two monitor setup, with 1 Retina and 1 non-Retina display, or a setup which has enabled HiDPI modes for non-Retina displays (the latter is how I reproduced this on a Mid-2011 27" iMac.

1. Install Xcode Version 7.1 (7B91b).
2. Unzip the attached zip file. 
3. In Xcode, open the attached SegmentedControlTest.xcodeproj.
4. Choose Product->Run.
5. In SegmentedControlTest, choose File->New.
6. Drag the window from a Retina to a non-Retina screen (alternatively, change the resolution in System Preferences->Display from normal to HiDPI mode, or vice versa).
-- Result: the window goes away. The Console output in Xcode will display the assertion failed message and stack trace shown in the Description.

Expected Results:
The window should stay on the screen, and properly resize.

Actual Results:
The window goes away (and will never come back without re-launching the app). 

Version:
Xcode Version 7.1 (7B91b)
Mac OS X 10.11.1 (15B42)

Notes:
Has something to do with autolayout, because removing all autolayout constraints makes the issue not occur. Is also specific to Separated style of NSSegmentedControl, as if it's set to any other style, the issue does not occur. Note that the enclosed sample app programmatically sets the segmented control to Separated style, because setting it in Xcode causes Xcode to crash (see possibly related rdar://23290250).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!