Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone上的NSString drawAtPoint崩溃(NSString drawAtPoint)_Iphone_Debugging_Crash_Nsstring - Fatal编程技术网

iPhone上的NSString drawAtPoint崩溃(NSString drawAtPoint)

iPhone上的NSString drawAtPoint崩溃(NSString drawAtPoint),iphone,debugging,crash,nsstring,Iphone,Debugging,Crash,Nsstring,嘿。我有一个非常简单的文本输出到缓冲系统,它将随机崩溃。几天内天气会很好,但有时几分钟内就会崩溃几次。对于使用更高级别控件的其他人来说,调用堆栈几乎完全相同: 它在以下行(以及drawTextToBuffer()中)崩溃: [nsString drawAtPoint:CGPointMake(0,0),带字体:clFont] 我有相同的“从缓存中逐出\u glyph\u entry\u”调用,后面紧接着中止调用 很明显,它发生在其他人身上。我可以说我的NSString*在崩溃时非常好。我可以很好

嘿。我有一个非常简单的文本输出到缓冲系统,它将随机崩溃。几天内天气会很好,但有时几分钟内就会崩溃几次。对于使用更高级别控件的其他人来说,调用堆栈几乎完全相同:

它在以下行(以及drawTextToBuffer()中)崩溃: [nsString drawAtPoint:CGPointMake(0,0),带字体:clFont]

我有相同的“从缓存中逐出\u glyph\u entry\u”调用,后面紧接着中止调用

很明显,它发生在其他人身上。我可以说我的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)中的异常

调用此函数后,
clFont
将被自动删除,因此不能保证与此函数无关的上下文仍然具有有效的
clFont
。如果以后打算使用实例,则需要保留它

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

谢谢你的快速回答。我试试看!
void selectFont(int iSize, NSString* sFont)
{
    iFontSize = iSize;
    [clFont release];
    clFont = [[UIFont fontWithName:sFont size:iFontSize] retain];
    iLineHeight = (int)(ceil([clFont capHeight]));
}