ios - App crashes on CGContext.drawPDFPage with a EXC_BAD_ACCESS
问题描述
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!
解决方案
iOS 12
任何遇到类似崩溃的人,情况都在缓存层中,按索引请求CGPDFDocument
,CGPDFPage
在特定情况下。
解决方案是按需从持久存储请求 PDF。
iOS 13
从 iOS 13 开始——我们没有看到任何与此相关的错误,因此 Apple 可能通过从值CGPDFDocument
和CGPDFPage
类型恢复上下文来解决该错误。
推荐阅读
- go - 如何获取主文件的目录
- java - Java BorderLayout:如何设置组件的首选大小
- powerbi - 计算从一开始直到选择切片器的 IRR,而其他指标仅针对该切片器选择
- node.js - 发生错误:APINestedStack - 未成功创建嵌入式堆栈 XYZ:未能创建以下资源:[...]
- html - Replicate Hackernoon url effect css
- javascript - react native如何知道API响应的Content-Type
- c# - msbuild Microsoft.NET.Sdk: how to override globbing?
- python-3.x - Discord.py @client.commands() unable to execute but @client.events can execute
- javascript - `await image.onload;` 是如何工作的?onload 为空,但等待等待 onload
- django - 加快 Django 发布请求的最佳方法?