• 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
CTLineGetTypographicBounds crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CTLineGetTypographicBounds crash


  • Subject: CTLineGetTypographicBounds crash
  • From: Koen van der Drift <email@hidden>
  • Date: Wed, 22 May 2013 09:05:00 -0400

I'm looking to add some highlighting to my Core Text View, and implemented the following which comes straight from Apple's SimpleTextInput code example (https://developer.apple.com/library/iOs/#samplecode/SimpleTextInput/Introduction/Intro.html):

// Helper method for drawing the current selection range (as a simple filled rect)
- (void)drawRangeAsSelection:(NSRange)selectionRange
{
	// If not in editing mode, we do not draw selection rects
    if (!self.editing)
        return;

    // If selection range empty, do not draw
    if (selectionRange.length == 0 || selectionRange.location == NSNotFound)
        return;

	// set the fill color to the selection color
    [[SimpleCoreTextView selectionColor] setFill];

	// Iterate over the lines in our CTFrame, looking for lines that intersect
	// with the given selection range, and draw a selection rect for each intersection
    NSArray *lines = (NSArray *) CTFrameGetLines(_frame);
    for (int i = 0; i < [lines count]; i++) {
        CTLineRef line = (CTLineRef) [lines objectAtIndex:i];
        CFRange lineRange = CTLineGetStringRange(line);
        NSRange range = NSMakeRange(lineRange.location, lineRange.length);
        NSRange intersection = [self RangeIntersection:range withSecond:selectionRange];
        if (intersection.location != NSNotFound && intersection.length > 0) {
			// The text range for this line intersects our selection range
            CGFloat xStart = CTLineGetOffsetForStringIndex(line, intersection.location, NULL);
            CGFloat xEnd = CTLineGetOffsetForStringIndex(line, intersection.location + intersection.length, NULL);
            CGPoint origin;
			// Get coordinate and bounds information for the intersection text range
            CTFrameGetLineOrigins(_frame, CFRangeMake(i, 0), &origin);
            CGFloat ascent, descent;
            CTLineGetTypographicBounds(line, &ascent, &descent, NULL);			<<<<<<<<<===========================  BOOM!
			// Create a rect for the intersection and draw it with selection color
            CGRect selectionRect = CGRectMake(xStart, origin.y - descent, xEnd - xStart, ascent + descent);
            UIRectFill(selectionRect);
        }
    }
}



But every time, I get an EXC_BAD_ACCESS error for the CTLineGetTypographicBounds() call.  I triple checked that _frame and line are valid at this point, and the debugger output shows what it is supposed to be (correct string, attributes, etc).

Here's the output from bt:

(lldb) bt
* thread #1: tid = 0x1c03, 0x0027bbd0 CoreText`CTLineGetTypographicBounds + 29, stop reason = EXC_BAD_ACCESS (code=2, address=0x60)
    frame #0: 0x0027bbd0 CoreText`CTLineGetTypographicBounds + 29
    frame #1: 0x000469a4 MyApp`-[MyView drawRangeAsSelection:](self=0x4576f000, _cmd=0x00000000, selectionRange=(null)) + 628 at MyView.m:461


Any suggestions why this could be happening?

Thanks,

- Koen.




_______________________________________________

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: CTLineGetTypographicBounds crash
      • From: Michael Babin <email@hidden>
  • Prev by Date: scroll UITableView
  • Next by Date: Re: CTLineGetTypographicBounds crash
  • Previous by thread: scroll UITableView
  • Next by thread: Re: CTLineGetTypographicBounds crash
  • Index(es):
    • Date
    • Thread