CoreText crashes when run in multiple threads

后端 未结 5 1587
-上瘾入骨i
-上瘾入骨i 2021-02-04 08:32

I have a very weird problem with core text, which sometimes randomly and sometimes reproducibly crashes my application. I use it to lay out and render a couple of pages. I do th

5条回答
  •  情深已故
    2021-02-04 08:58

    fix from me :-) no crash anymore

    old code

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:aText];
    [attributedString addAttribute:(id)kCTFontAttributeName value:(id)aFontRef range:NSMakeRange(0, [aText length])];
    
    CTFramesetterRef framesetterRef = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);
    

    new code

    CFMutableAttributedStringRef attributedStringRef = CFAttributedStringCreateMutable(nil, 0);
    CFAttributedStringBeginEditing(attributedStringRef);
    CFAttributedStringReplaceString(attributedStringRef, CFRangeMake(0, 0), (CFStringRef)aText);
    CFAttributedStringSetAttribute(attributedStringRef, CFRangeMake(0, aText.length), kCTFontAttributeName, aFontRef);
    CFAttributedStringEndEditing(attributedStringRef);
    
    CTFramesetterRef framesetterRef = CTFramesetterCreateWithAttributedString(attributedStringRef); 
    

提交回复
热议问题