iphone - CTTypesetter 在奇怪的 Unicode 字符上崩溃

标签 iphone objective-c ios ipad core-text

我正在使用 CTTypesetter 来布局从服务器读取的 JSON 消息。但是,在某些特定的消息上它会崩溃,即那些具有异常 Unicode 字符的消息,如下所示。

CFAttributedStringRef attrString = CFAttributedStringCreate(NULL, @"❝We  must  learn  to  live  together  as  brothers  or  perish  together  as  fools❞ ~Martin Luther King Jr. #HappyMLKDay", nil);
CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString(attrString);

这会因以下堆栈跟踪而崩溃。

#0  0x33a4684e in TBaseFont::CopyCharacterSet() const ()
#1  0x33a2c0d4 in CompareCharSet(__CFCharacterSet const*, TBaseFont const*) ()
#2  0x33a2f03e in TDescriptorSource::CopyDescriptorsForRequestFromArray(__CFArray const*, __CFDictionary const*, long (*)(void const*, void const*, void*), void*, unsigned long, bool) const ()
#3  0x33a2ead0 in TDescriptorSource::CopyDescriptorsForRequest(__CFDictionary const*, __CFSet const*, long (*)(void const*, void const*, void*), void*, unsigned long) const ()
#4  0x33a2e624 in TDescriptorSource::CopyDescriptorForRequest(__CFDictionary const*, __CFSet const*, long (*)(void const*, void const*, void*), void*, unsigned long) const ()
#5  0x33a2e532 in TDescriptorSource::CopySystemWideFallbackDescriptor(CGFont*, unsigned short const*, long) const ()
#6  0x33a2e79c in TDescriptorSource::CopySystemWideFallbackDescriptor(CGFont*, __CFString const*, CFRange) const ()
#7  0x33a27c78 in TFontCascade::CreateSystemWideFallback(__CTFont const*, __CFString const*, CFRange) const ()
#8  0x33a27b28 in TFontCascade::CreateFallback(__CTFont const*, __CFString const*, CFRange) const ()
#9  0x33a185ec in TGlyphEncoder::AppendUnmappedCharRun(CTRun*, CFRange, CFRange, TGlyphList<TDeletedGlyphIndex>&, TGlyphList<TDeletedGlyphIndex>&, TFontCascade const&, bool) ()
#10 0x33a184b8 in TGlyphEncoder::RunUnicodeEncoderRecursively(CTRun*, adopted_t const&, CFRange, TGlyphList<TDeletedGlyphIndex>&, TGlyphList<TDeletedGlyphIndex>&, TFontCascade const*, bool) ()
#11 0x33a186e4 in TGlyphEncoder::AppendUnmappedCharRun(CTRun*, CFRange, CFRange, TGlyphList<TDeletedGlyphIndex>&, TGlyphList<TDeletedGlyphIndex>&, TFontCascade const&, bool) ()
#12 0x33a184b8 in TGlyphEncoder::RunUnicodeEncoderRecursively(CTRun*, adopted_t const&, CFRange, TGlyphList<TDeletedGlyphIndex>&, TGlyphList<TDeletedGlyphIndex>&, TFontCascade const*, bool) ()
#13 0x33a1824c in TGlyphEncoder::RunUnicodeEncoder(CTRun*, adopted_t const&, CFRange, TGlyphList<TDeletedGlyphIndex>&, TFontCascade const*) ()
#14 0x33a07a1a in TGlyphEncoder::EncodeChars(CFRange, TAttributes const&, TGlyphList<TDeletedGlyphIndex>&, TGlyphEncoder::Fallbacks) ()
#15 0x33a0665c in TTypesetterAttrString::Initialize(__CFAttributedString const*) ()
#16 0x33a064a4 in TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*) ()
#17 0x33a06418 in TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*) ()
#18 0x33a1e78c in CTTypesetterCreateWithAttributedString ()

我创建了一个空项目来尝试重现崩溃,但是在这个环境中它工作正常。

文档是这样说的:

Multicore Considerations: All individual functions in Core Text are thread safe. Font objects (CTFont, CTFontDescriptor, and associated objects) can be used by simultaneously by multiple operations, work queues, or threads. However, the layout objects (CTTypesetter, CTFramesetter, CTRun, CTLine, CTFrame, and associated objects) should be used in a single operation, work queue, or thread.

为此,我移除了所有类型的线程,即一些 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ...),试图解决这个问题。我不知道除了破坏 >20 KSLOC 项目之外我还能尝试解决什么问题。

它只会让实际的 iPad 崩溃(所有 3 个型号都使用 5.0 和 5.1 进行测试),而不是模拟器。

我可以尝试解决这个问题吗?我打算求助于嵌入 Helvetica 的修改版本,并将尽可能多的后备字体合并到其中,但这远非最佳解决方案。


任何意见都将不胜感激,正如您所见,自一月份以来,这一直让我抓狂!

最佳答案

我刚刚解决了它。

我在 info.plist 中引用了 43 种字体。所有这些都是有效的,在我的资源包中都是 otf 或 ttf。我刚删除了一些,它就开始工作了。

该死的 Apple 错误。

关于iphone - CTTypesetter 在奇怪的 Unicode 字符上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8882961/

相关文章:

iphone - XML 阅读器类中讨厌的新行和空格

ios - 是否可以在 Afnetworking POST 方法中发布字典数组?

ios - InfoPlist.strings 与常量的 global.h

iphone - SKPayment paymentWithProductIdentifier 已弃用。备择方案?

ios - 如何在 Swift 中显示文档目录中的贴纸

ios - Swift iOS 10 的推送通知

iphone - Settings.app 中的应用程序首选项

iphone - 如何以编程方式创建横向 UIView?

ios - 谷歌地图的自定义标记图标不可点击(使用委托(delegate))

iPhone - 帮助使用 MBProgressHUD、Sudzc、Web 服务和 NSThread