• 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
NSAttributedString attribute:atIndex:effectiveRange crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAttributedString attribute:atIndex:effectiveRange crash


  • Subject: NSAttributedString attribute:atIndex:effectiveRange crash
  • From: Greg Hoover <email@hidden>
  • Date: Tue, 16 Oct 2007 15:02:42 -0700

I'm using the following code to figure out where a click occurred in an attributed string that's displayed.

// Now layout the string to figure out where in the string the click occurred
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString: string];
[string release];
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithContainerSize: [textStorage size]];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];

[layoutManager addTextContainer: textContainer];
[textStorage addLayoutManager: layoutManager];

// force layout
[layoutManager glyphRangeForTextContainer: textContainer];

int glyphIndex = [layoutManager glyphIndexForPoint: [point pointValue]
inTextContainer: textContainer];
int charIndex = [layoutManager characterIndexForGlyphAtIndex: glyphIndex];

[layoutManager release];
[textContainer release];

NSRangePointer range;
id attribute = nil;
if (charIndex < [textStorage length])
attribute = [textStorage attribute: NSLinkAttributeName
atIndex: charIndex
effectiveRange: range];
NSURL *url = nil;
if (attribute)
url = [attribute copy];
[textStorage release];


The problem is that half the time it crashes with EXC_BAD_ACCESS and this stack trace:

#0 0x927fff1e in blockForLocation
#1 0x927ffe9a in -[NSRLEArray objectAtIndex:effectiveRange:]
#2 0x928003fc in -[NSConcreteMutableAttributedString attribute:atIndex:effectiveRange:]
#3 0x93377c7f in -[NSConcreteTextStorage attribute:atIndex:effectiveRange:]


I can't seem to find any info related to blockForLocation or figure out what the problem is. Any help would be much appreciated.

Thanks in advance,

Greg
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSAttributedString attribute:atIndex:effectiveRange crash
      • From: Dave Fernandes <email@hidden>
  • Prev by Date: Fw: TableView not loading completely
  • Next by Date: Re: Cocoa-dev Digest, Vol 4, Issue 1017
  • Previous by thread: can ABPeoplePicker look disabled
  • Next by thread: Re: NSAttributedString attribute:atIndex:effectiveRange crash
  • Index(es):
    • Date
    • Thread