Crash on Sequoia 15.2

Starting from Sequoia release 15.2 apps crash with following call stack, when adding static text controls. First call to [NSTextField setStringValue] causes following crash

0 libobjc.A.dylib 0x19f2f5820 objc_msgSend + 32

1 AppKit 0x1a3355460 -[NSCell _objectValue:forString:errorDescription:] + 144

2 AppKit 0x1a3355348 -[NSCell setStringValue:] + 48

3 AppKit 0x1a33af9fc -[NSControl setStringValue:] + 104

4 AppKit 0x1a3d1f190 -[NSTextField setStringValue:] + 52

It happens on specific MacBook Pro models(16 in MacBook Pro).
Crash analysis found that isa pointer of the object was corrupted for the object NSCell. Enabled Zombies in debugging, not found any issue. Also tried address sanitizer. Since the issue started with a recent release of macOS, any changes in the Appkit in the recent releases trigger the crash? Any help/suggestions would be appreciated.

Could you show the part of code where it crashed ?

Is it ObjC or Swift ? SwiftUI ?

Have you a minimal project to share that reproduces the crash ?

Sharing the code snippet. As per the following code, -setText should not set property self.stringValue. Instead it should set self.attributedStringValue. But the crash log we see that crash occurs inside call to setStringValue

// Create the text field NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(x, y, width, height)]; // Use the system font using the standard size textField.font = [NSFont labelFontOfSize:[NSFont systemFontSize]]; textField.textColor = [NSColor textColor]; [textField setStatic]; [textField setID:idControl]; [textField setText:szText];

@implementation NSTextField(NSTextFieldAdditions)

  • (void) setStatic

{ self.alignment = NSLeftTextAlignment; self.bordered = NO; self.drawsBackground = NO; self.bezeled = NO; self.editable = NO; self.selectable = NO; }

  • (void) setText:(const tchar*)szText

{ LFTRACE("Text:", szText);

// If an input control then use the unstyled text. If a static control then use the attributed text if ((self.isEditable) || (self.isSelectable) || (self.drawsBackground)) { self.stringValue = [NSString stringWithUTF8String:szText]; } else { NSMutableAttributedString* attrStringMutable = [[[NSMutableAttributedString alloc] initWithString:nszText attributes:attrDic] autorelease]; self.attributedStringValue = attrStringMutable; }

Sorry for bad formatting of the code. The crash is not reproduced on my Mac. It is produced on customer machines. It frequency is low but if it produced on a particular Mac it always consistently produced on that Mac. So I think it is hardware dependent.

// Create the text field 
NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(x, y, width, height)]; 
// Use the system font using the standard size 
textField.font = [NSFont labelFontOfSize:[NSFont systemFontSize]]; 
textField.textColor = [NSColor textColor]; 
[textField setStatic]; 
[textField setID:idControl];
[textField setText:szText];  //  <== crash in this function



@implementation NSTextField(NSTextFieldAdditions)
(void) setStatic
{ 
   self.alignment = NSLeftTextAlignment; 
   self.bordered = NO; 
   self.drawsBackground = NO; 
   self.bezeled = NO; 
   self.editable = NO; 
   self.selectable = NO; 
}

(void) setText:(const tchar*)szText
{ 
// If an input control then use the unstyled text. If a static control then use the attributed text 
if ((self.isEditable) || (self.isSelectable) || (self.drawsBackground)) {    // <== Always take this path which should not happen
   self.stringValue = [NSString stringWithUTF8String:szText]; 
} else { 
    NSMutableAttributedString* attrStringMutable =        [[[NSMutableAttributedString alloc] initWithString:nszText attributes:attrDic] autorelease]; 
   self.attributedStringValue = attrStringMutable; 
}

Crash on Sequoia 15.2
 
 
Q