NSWindow Suddenly Closes After NSTextField Ends Editing (By Clicking into Another NSTextField)

Configuration:

  1. I have a NSTextField (multiline) inside an NSWindow.
  2. I have another NSTextField (single line) inside an NSBox (which is in the same window).
  3. The multiline text field is first responder and is editing.
  4. I click on the single line text field inside the NSBox to edit that one.
  5. The NSWindow just closes.

This is on Sonoma 14.2.1.

I subclassed NSWindow and override the close method and put a breakpoint.

Here's the call stack that leads to the window suddenly closing:

#1	0x0000000189c73d90 in -[NSWindow __close] ()
#2	0x000000032343 in -[NSApplication(NSResponder) sendAction:to:from:] ()
#3	0x0000000189b543ac in -[NSControl sendAction:to:] ()
#4	0x0000000189b542f0 in __26-[NSCell _sendActionFrom:]_block_invoke ()
#5	0x0000000189b54218 in -[NSCell _sendActionFrom:] ()
#6	0x0000000189b5413c in -[NSButtonCell _sendActionFrom:] ()
#7	0x0000000189c4c508 in __29-[NSButtonCell performClick:]_block_invoke ()
#8	0x0000000189c4c264 in -[NSButtonCell performClick:] ()
#9	0x0000000189b545a8 in -[NSApplication(NSResponder) sendAction:to:from:] ()
#10	0x0000000189b543ac in -[NSControl sendAction:to:] ()
#11	0x0000000189befb48 in -[NSTextField textDidEndEditing:] ()
#12	0x0000000__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#13	0x000000018625c65c in ___CFXRegistrationPost_block_invoke ()
#14	0x000000018625c5a4 in _CFXRegistrationPost ()
#15	0x00000001861971dc in _CFXNotificationPost ()
#16	0x0000000187289ff0 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#17	0x0000000189bef754 in -[NSTextView(NSSharing) resignFirstResponder] ()
#18	0x0000000189a9fab8 in -[NSWindow _realMakeFirstResponder:] ()
#19	0x0000000189b4f18c in -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] ()
#20	0x0000000189ada79c in -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] ()
#21	0x0000000189ada45c in -[NSWindow(NSEventRouting) sendEvent:] ()
#22	0x000000018a1879f4 in -[NSApplication(NSEventRouting) sendEvent:] ()
#23	0x0000000189dd6908 in -[NSApplication _handleEvent:] ()
#24	0x00000001899a1d74 in -[NSApplication run] ()

The mouse click is no where near the close button in the title bar.

Using the tab key to change from editing the multiline text field to the single line text field also causes the window to close so using the mouse is not required to reproduce the bug.

Here is a workaround:

// In a NSTextField subclass.
-(BOOL)sendAction:(SEL)action to:(id)target
{
    if (action == @selector(performClose:))
    {
        return NO;
    }
    else
    {
        return [super sendAction:action to:target];
    }
}
NSWindow Suddenly Closes After NSTextField Ends Editing (By Clicking into Another NSTextField)
 
 
Q