【问题标题】:NSString drawAtPoint Crash on the iPhone (NSString drawAtPoint)iPhone上的NSString drawAtPoint崩溃(NSString drawAtPoint)
【发布时间】:2010-04-02 07:19:56
【问题描述】:

嘿。我有一个非常简单的文本输出到缓冲系统,它会随机崩溃。 DAYS 没问题,然后有时会在几分钟内崩溃几次。对于使用更高级别控件的其他人来说,调用堆栈几乎完全相同: http://discussions.apple.com/thread.jspa?messageID=7949746 iPhone app crashed: Assertion failed function evict_glyph_entry_from_strike, file Fonts/CGFontCache.c

它在该行崩溃(在下面的 drawTextToBuffer() 中也是如此): [nsString drawAtPoint:CGPointMake(0, 0) withFont:clFont];

我有相同的“evict_glyph_entry_from_cache”调用,紧接着是中止调用。

显然它发生在其他人身上。我可以说我的 NSString* 在崩溃时非常好。我可以很好地从调试器中读取文本。

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);
}

其他非 unicode 支持方法也会发生这种情况,例如 CGContextShowTextAtPoint();调用堆栈也与此类似。

这是 iPhone 的任何已知问题吗?或者,也许,这个原因之外的东西会导致这个特定调用 (drawAtPoint) 中的异常?

【问题讨论】:

    标签: iphone debugging crash nsstring


    【解决方案1】:
    void selectFont(int iSize, NSString* sFont)
    {
        iFontSize = iSize;
        clFont = [UIFont fontWithName:sFont size:iFontSize];
        iLineHeight = (int)(ceil([clFont capHeight]));
    }
    

    调用此函数后,clFont 将被自动释放,因此无法保证与此函数无关的上下文仍然可以具有有效的clFont。如果您打算稍后使用它,则需要 -retain 一个实例。

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

    【讨论】:

    • 感谢您的快速回答。我会试试看!
    猜你喜欢
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 2014-12-12
    • 2019-05-15
    相关资源
    最近更新 更多