Exception when opening NSPopover if existing detached firstResponder

Originator:aufflick
Number:rdar://12465816 Date Originated:10/10/12
Status:New Resolved:
Product:Developer Tools Product Version:Xcode 4.5.1
Classification:Serious Bug (aren't they all!) Reproducible:Always
 
10-Oct-2012 11:39 AM Mark Aufflick:
Summary:

If you have an NSPopover with something as first responder (eg. an NSTextField) that has been detached to a window, and then attempt to open another similar NSPopover, an exception occurs and the second NSPopover does not open:

NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.

Steps to Reproduce:

1. Open an NSPopover with an NSTextField.
2. Detach it to a window
3. Attempt to open a new NSPopover that also has an NSTextField

Expected Results:

NSPopover shows.

Actual Results:

No NSPopover, and logs show exception:

2012-10-10 10:31:00.069 PopoverTest[30774:303] NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.
2012-10-10 10:31:00.074 PopoverTest[30774:303] (
	0   CoreFoundation                      0x00007fff8c62c0a6 __exceptionPreprocess + 198
	1   libobjc.A.dylib                     0x00007fff8ce003f0 objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff8c62be7c +[NSException raise:format:] + 204
	3   AppKit                              0x00007fff93606cf9 -[NSWindow _newFirstResponderAfterResigning] + 117
	4   AppKit                              0x00007fff936068cf -[NSTextView(NSSharing) resignFirstResponder] + 53
	5   AppKit                              0x00007fff934d07d8 -[NSWindow makeFirstResponder:] + 430
	6   AppKit                              0x00007fff93a030a2 -[NSWindow _makeParentWindowHaveFirstResponder:] + 51
	7   AppKit                              0x00007fff934d067a -[NSWindow makeFirstResponder:] + 80
	8   AppKit                              0x00007fff934f6ad8 -[NSWindow _selectFirstKeyView] + 812
	9   AppKit                              0x00007fff934f678b -[NSWindow _setUpFirstResponder] + 182
	10  AppKit                              0x00007fff934f4abf -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 1288
	11  AppKit                              0x00007fff934f3f7c -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 496
	12  AppKit                              0x00007fff934f3d1f -[NSWindow orderWindow:relativeTo:] + 159
	13  AppKit                              0x00007fff935c12b1 -[NSWindow addChildWindow:ordered:] + 924
	14  AppKit                              0x00007fff93b951a4 -[NSPopover showRelativeToRect:ofView:preferredEdge:] + 1693
	15  PopoverTest                         0x00000001000016d9 -[PTYAppDelegate button2:] + 601
	16  AppKit                              0x00007fff93524a59 -[NSApplication sendAction:to:from:] + 342
	17  AppKit                              0x00007fff935248b7 -[NSControl sendAction:to:] + 85
	18  AppKit                              0x00007fff935247eb -[NSCell _sendActionFrom:] + 138
	19  AppKit                              0x00007fff93522cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
	20  AppKit                              0x00007fff93522521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
	21  AppKit                              0x00007fff93521c9c -[NSControl mouseDown:] + 820
	22  AppKit                              0x00007fff9351960e -[NSWindow sendEvent:] + 6853
	23  AppKit                              0x00007fff93515744 -[NSApplication sendEvent:] + 5761
	24  AppKit                              0x00007fff9342b2fa -[NSApplication run] + 636
	25  AppKit                              0x00007fff933cfcb6 NSApplicationMain + 869
	26  PopoverTest                         0x00000001000011d2 main + 34
	27  libdyld.dylib                       0x00007fff924427e1 start + 0
)

Regression:

I'm pretty confident this didn't happen with the SDK shipped with 4.5.0.

Notes:

I have attached a sample project that demonstrates the issues if you follow the steps above.
#For OpenRadar readers, here's the sample app: https://dl.dropbox.com/u/12615608/PopoverTest%20Project.zip

If the NSPopovers have nothing capable of being first responder it works fine.

Comments

More weird.

To make things even more weird, while the sample project attached earlier exhibits the problem on both my iMac and MBP Retina, my actual application does not exhibit the bug on my iMac but does on my MBP Retina. Trying to think of the differences between the devices, I've tried integrated and discrete graphics and HiDPI vs. non-HiDPI with no effect. Which machine the binary is built on makes no difference, only which machine it runs on. My Retina MBP was fresh out of the box last week (which was also, not coincidentally, when I first noticed the bug).

Both have Xcode Version 4.5.1 (4G1004) and OSX 10.8.2 Build 12C60.

Simpler reproduction of issue

In fact, it's even simpler to reproduce with no need for a second NSPopover.

It happens as soon as something attempts to take firstResponder. In the attached sample code if you detach the nspopover and then click into the text field in the main window you get the same exception.

I note that the Apple sample Popover project does not have this issue using a static window from a nib, but whenever I try to achieve it with a manually created window I see the issue.

Also I tried compiling under Xcode 4.5.0 and the same problem occurs, so perhaps it's not a regression.

I've attached the simpler project demonstrating the issue.

For OpenRadar here's the project: https://dl.dropbox.com/u/12615608/PopoverTest2.zip


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!