Crash while rendering glyphs in iOS 14

I've a custom UIView to render a large piece of text using CATiledLayers. My draw(rect:) implementation is quite simple:

Code Block swift
override func draw(_ rect: CGRect) {
let range = layoutManager.glyphRange(forBoundingRect: rect, in: textContainer)
layoutManager.drawBackground(forGlyphRange: range, at: .zero)
layoutManager.drawGlyphs(forGlyphRange: range, at: .zero)
}


This code works without any issue on iOS 13, but fails with a crash on iOS 14 simulator:

Code Block
Thread 9: EXC_BAD_ACCESS (code=1, address=0x28)
#0 0x00007fff2396a3f5 in _NSLayoutTreeMoveToGlyphIndex ()


I can see that draw(rect:) is being called from different threads in both iOS 13 and 14. However the EXC_BAD_ACCESS has never happened so far in iOS 13.

I wonder whether this is a behaviour change in iOS 14 or an issue. If this is a change in NSLayoutManager, then is it still possible to use CATiledLayer to render large amount of text in coordination with NSLayoutManager?

Replies

Hi @haldun-gh did you get any fix or solution to this? I am facing the same thing on iOS 17 but it was working fine on iOS 15.5 device.