CoreText在多线程中运行时崩溃 [英] CoreText crashes when run in multiple threads

查看:525
本文介绍了CoreText在多线程中运行时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常古怪的核心文本的问题,有时随机,有时可重复性崩溃我的应用程序。我使用它来布局和渲染几页。我在后台异步执行此操作以不阻止用户界面。

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 this asynchronously in the background to not block the user interface.

虽然这通常工作正常,但有时候崩溃。所有这些事故发生在非常相同的路线:

While this works fine in general, it sometimes crashes. All these crashes happen on the very same line:

framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)myText);

事实上,他们也似乎来自框架中的类似点。我知道你不喜欢它,但这是崩溃日志的头:

In fact, they also also seem to come from a similar point in the framework. I know you don't like it, but here's the head of a crash log:

Thread 8 Crashed:
0   ???                             0x0764f446 typeinfo for FT::data_stream + 6
1   libCGFreetype.A.dylib           0x076048b8 FT::font::copy_table(unsigned int) const + 94
2   libCGFreetype.A.dylib           0x0760b085 (anonymous namespace)::copy_table(void*, unsigned int) + 53
3   CoreText                        0x00f9592e TBaseFont::CopyTable(unsigned int) const + 334
4   CoreText                        0x00f670f6 TAATMorphTable::TAATMorphTable(TLine&, long, unsigned int) + 110
5   CoreText                        0x00f6744c TAATMorphTableMorx::TAATMorphTableMorx(TLine&, long, TGlyphList<TDeletedGlyphIndex>&) + 54
6   CoreText                        0x00f53eb5 TShapingEngine::ShapeGlyphs(TLine&, TCharStream const&, CFRange&, TGlyphList<TDeletedGlyphIndex>*) + 215
7   CoreText                        0x00f579ce TTypesetter::FinishEncoding(TLine&, signed char, TGlyphList<TDeletedGlyphIndex>*) const + 260
8   CoreText                        0x00f6664b TTypesetterAttrString::Initialize(__CFAttributedString const*) + 543
9   CoreText                        0x00f6683e TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*) + 158
10  CoreText                        0x00f6102e TFramesetterAttrString::TFramesetterAttrString(__CFAttributedString const*) + 86
11  CoreText                        0x00f6099e CTFramesetterCreateWithAttributedString + 78
...

我记得的所有崩溃都在 FT :: font :: copy_table 函数。有趣的是,字体要求越复杂,崩溃越频繁。中文文本几乎总是崩溃 - 这些字体似乎很复杂。

All crashes I can remember have been in the FT::font::copy_table function. Interestingly, the more complicated the font-requirements, the more frequent the crashes. Chinese text nearly always crash -- those fonts seem to be quite complicated.

解决方法:我找到的解决方法是将调用顺序 CTFramesetterCreateWithAttributedString 在主队列或单独的一个。问题是,这个单个调用占总布局和渲染运行时间的79%。所以我很想拥有它在多个线程。

Workaround: The workaround I found is to sequentialize the calls to CTFramesetterCreateWithAttributedString in either the main queue or a separate one. The problem is that this single call makes up 79% of the total layout and rendering running time. So I would love to have it in multiple threads.

问题:任何优点,可以帮助? 对我来说,这听起来像是一个深处的竞争条件。我没有找到任何说明CoreText可能不使用线程。我明天会提出一个错误。但是,我也可能错过了一些东西。任何建议?

Question: Any Pros around that could help? To me this sounds like a race condition somewhere deep down. I didn't find anything stating that CoreText may not be used threaded. And I will file a bug tomorrow. However, I might also just have missed something. Any advice?

感谢,
最大

推荐答案

我问过WWDC期间的一些工程师,他们是否知道这个问题。答案:是的。事实上,在类型子系统中存在一些问题。他们可能在某天做一个修复,但现在,剩下要做的是顺序化所有的文本布局。 :(

I've asked some of the engineers during WWDC whether they know the issue. The answer: YES. And there are in fact some problems in the type subsystem. They might be doing a fix some day, but for now all that is left to do is to sequentialize all text layout. :(

每个人:请提交文件BUGS!

这篇关于CoreText在多线程中运行时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆