开发者

NSString drawAtPoint Crash on the iPhone (NSString drawAtPoint)

Hey. I have a very simple text output to buffer system which will crash randomly. It will be fine for DAYS, then sometimes it'll crash a few times in a few minutes. The callstack is almost exactly the same for other guys who use higher level controls: http://discussions.apple.com/thread.jspa?messageID=7949746 iPhone app crashed: Assertion failed function evict_glyph_entry_from_strike, file Fonts/CGFontCache.c

It crashes at the line (below as well in drawTextToBuffer()): [nsString drawAtPoint:CGPointMake(0, 0) withFont:clFont];

I have the same call of "evict_glyph_entry_from_cache" with the abort calls immediately following it.

Apparently it happens to other people. I can say that my NSString* is perfectly fine at the time of the crash. I can read the text from the debugger just fine.

static CGColorSpaceRef curColorSpace;
static CGContextRef myContext;
static float w, h;
static int iFontSize;
static NSString* sFontName;
static UIFont* clFont;
static int iLineHeight;

unsigned long* txb; /* 256x256x4 Buffer */


void selectFont(int iSize, NSString* sFont)
{
    iFontSize = iSize;
    clFont = [UIFont fontWithName:sFont size:iFontSize];
    iLineHeight = (int)(ceil([clFont capHeight]));
}


void initText()
{
    w = 256;
    h = 256;

    txb = (unsigned long*)malloc_(w * h * 4);

    curColorSpace = CGColorSpaceCreateDeviceRGB();
    myContext = CGBitmapContextCreate(txb, w, h, 8, w * 4, curColorSpace, kCGImageAlphaPremultipliedLast);

    selectFont(12, @"Helvetica");
}

void drawTextToBuffer(NSString* nsString)
{
    CGContextSaveGState(myContext);
    CGContextSetRGBFillColor(myContext, 1, 1, 1, 1);
    UIGraphicsPushContext(myContext);

    /* This line will crash.  It crashes even with constant Strings..   At the time of the crash, the pointer to nsString is perfectly fine.  The data looks fine! */
    [nsString drawAtPoint:CGPointMake(0, 0) withFont:clFont];
    UIGraphicsPopContext();
    CGContextRestoreGState(myContext);
}

It will happen with other non-unicode supporting methods as well such as CGContextShowTextAtPoint(); the callstack is similar with that as well.

Is this any kind of known issue with the iPhone? Or, perhaps, can something outside of this cause be causing an exception in this particular call (dra开发者_运维百科wAtPoint)?


void selectFont(int iSize, NSString* sFont)
{
    iFontSize = iSize;
    clFont = [UIFont fontWithName:sFont size:iFontSize];
    iLineHeight = (int)(ceil([clFont capHeight]));
}

After calling this function, clFont will be autoreleased, so there's no guarantee that a context irrelevant to this function can still have a valid clFont. You need to -retain an instance if you plan to use it later.

void selectFont(int iSize, NSString* sFont)
{
    iFontSize = iSize;
    [clFont release];
    clFont = [[UIFont fontWithName:sFont size:iFontSize] retain];
    iLineHeight = (int)(ceil([clFont capHeight]));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜