My app is randomly crashing on CGContext.drawPDFPage without a way to reproduce the bug consistently. It happens mostly on iPads. The code looks something like this:
override func draw(_ layer: CALayer, in ctx: CGContext) {
UIGraphicsPushContext(ctx)
ctx.saveGState()
defer {
ctx.restoreGState()
UIGraphicsPopContext()
}
ctx.setFillColor(UIColor.white.cgColor)
ctx.fill(viewBounds)
ctx.translateBy(x: 0, y: viewBounds.height)
ctx.scaleBy(x: 1, y: -1)
ctx.scaleBy(x: pdfScale, y: pdfScale)
ctx.interpolationQuality = .high
ctx.setRenderingIntent(.defaultIntent)
ctx.beginPDFPage(nil)
ctx.drawPDFPage(pdfPage) // This is where the crash happens
ctx.endPDFPage()
}
The stack trace ends in CGPDFObjectGetReference and looks like this:
The error is: EXC_BAD_ACCESS. If you see anything that could be causing this crash would help me a lot!
