• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Cocoa Text Handling Crashes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa Text Handling Crashes


  • Subject: Cocoa Text Handling Crashes
  • From: Andrew Thompson <email@hidden>
  • Date: Mon, 6 Jan 2003 21:38:22 -0500

I've been having some issues with the text rendering system in cocoa crashing and taking me application out.

In particular, I find its quite easy to get it to die by accidentally asking an NSCell subclass to render an NSAttributedString with only one character. The key problems occur if the character turns out to be mapped to NSNullGlyph in the current font and for some characters whose bounding box is an empty rectangle.

To compensate, I've developed this class category for NSFont:

@implementation NSFont (UFIFont)

- (BOOL) unicharIsRenderable: (unichar) a_char {
NSAttributedString *charString = [[NSAttributedString alloc] autorelease];
[charString initWithString: [NSString stringWithCharacters: &a_char length: 1]
attributes: [self makeFontDictionary]];
BOOL result = NO;

if ( charString != nil && ![@"" isEqual: charString] ) {
NSTextStorage *chars = [[NSTextStorage alloc] initWithAttributedString: charString];
NSLayoutManager *man = [[NSLayoutManager alloc] init];
[chars addLayoutManager: man];
[man release]; //see [1]

if ( [man numberOfGlyphs] > 0 ) {
NSGlyph g = [man glyphAtIndex: 0];
//detect garbage glyphs, which have a bad habit of breaking the layout system
result = [self glyphIsEncoded: g] && (g != NSNullGlyph) && !NSEqualRects([self boundingRectForGlyph: g], NSZeroRect);
}
[chars release];
}
return result;
}

- (NSDictionary *) makeFontDictionary {
return [NSDictionary dictionaryWithObjectsAndKeys: self, NSFontAttributeName, nil];
}

@end

This essentially determines whether its safe to render the unichar 'a_char' in question as the title for an NSCell, or whether its likely to crash my app.

The symptoms are various, from bounds assertion failures, to visual corruption of on-screen controls, to eventually spinning cursor of death or even the occasional Segmentation Fault.

It should be noted that its much easier to reproduce these problems if you have titles with only one character in them. If the character is part of a large string with some valid content, things seem to work much better (as in crash less, and take longer to crash). This may be because some of the bad glyphs include the combining diacritical marks which ArialMT claims to have but really doesn't seem to.

I can probably boil this down to a simple test project and get a stack trace. Would this be valuable or do you have enough of a handle on these issues that I need not spend the time?

AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside

(see you later space cowboy ...)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Cocoa Text Handling Crashes
      • From: Andrew Thompson <email@hidden>
    • Re: Cocoa Text Handling Crashes
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: Working with 32-bit Unicode (NSString stringWithUTF32String: (const UTF32Char *) bytes needed)
  • Next by Date: Re: Addressbook framework without a regular user
  • Previous by thread: Dock Menu Bugs
  • Next by thread: Re: Cocoa Text Handling Crashes
  • Index(es):
    • Date
    • Thread