Posts

Post not yet marked as solved
2 Replies
2.5k Views
Hi,in our app we render PDF pages with a CATiledLayer to screen. We have occasional crashes mostly on iPads. Every time it crashes there are two or three concurrent threads rendering the page. I'm not able to reproduce it.Any idea how to fix this?Code looks like this: override func draw(_ layer: CALayer, in ctx: CGContext) { guard let page = self.page else { return } ctx.setFillColor(red: 1.0,green: 1.0,blue: 1.0,alpha: 1.0) ctx.fill(ctx.boundingBoxOfClipPath) let layerSize = layer.bounds.size // Flip the context so that the PDF page is rendered right side up. ctx.translateBy(x: 0.0, y: layerSize.height) ctx.scaleBy(x: 1.0, y: -1.0) let pageMediaBox = page.getBoxRect(.mediaBox) let fillWithPDFPageVerticalProportion = layerSize.height / pageMediaBox.height let fillWithPDFPageHorizontalProportion = layerSize.width / pageMediaBox.width let fillWithPDFPageProportion = min(fillWithPDFPageVerticalProportion, fillWithPDFPageHorizontalProportion) ctx.translateBy( x: -(pageMediaBox.width * fillWithPDFPageProportion - layerSize.width) / 2, y: -(pageMediaBox.height * fillWithPDFPageProportion - layerSize.height) / 2 ) ctx.scaleBy(x: fillWithPDFPageProportion, y: fillWithPDFPageProportion) ctx.drawPDFPage(page) }This is a stack trace from the crashing thread:#8. Crashed: com.apple.root.default-qos0 libobjc.A.dylib 0x185a8c1a0 objc_retain + 161 ImageIO 0x1888dd5cc IIOImageRead::IIOImageRead(CGDataProvider*, bool) + 882 ImageIO 0x1888df93c CGImageReadCreateWithProvider + 1963 ImageIO 0x18874ac6c IIOImageSource::IIOImageSource(CGDataProvider*, IIODictionary*) + 964 ImageIO 0x18874ec50 CGImageSourceCreateWithDataProvider + 1725 CoreGraphics 0x18803a464 CGImageCreateWithJPEGDataProvider3 + 846 CoreGraphics 0x187fb7264 create_image_for_image + 1887 CoreGraphics 0x187fb713c CGPDFImageCreateImage + 1848 CoreGraphics 0x1880256f8 CGPDFDrawingContextDrawImage + 409 CoreGraphics 0x1880de03c op_Do + 10410 CoreGraphics 0x1882e6684 pdf_scanner_handle_xname + 14411 CoreGraphics 0x1882e5f0c CGPDFScannerScan + 36812 CoreGraphics 0x1882f0170 CGPDFDrawingContextDrawPage + 51613 CoreGraphics 0x1880c0a04 pdf_page_draw_in_context + 13214 CoreGraphics 0x187fa763c CGContextDrawPDFPageWithDrawingCallbacks + 7615 CoreGraphics 0x187fa7310 CGContextDrawPDFPage + 3216 myApp 0x1009e8cf0 specialized PDFTiledView.draw(CALayer, in : CGContext) -> () (PDFTiledView.swift:59)17 myApp 0x1009e88ec @objc PDFTiledView.draw(CALayer, in : CGContext) -> () (PDFTiledView.swift)18 QuartzCore 0x18a86b51c -[CALayer drawInContext:] + 29619 QuartzCore 0x18a79c780 tiled_layer_render(_CAImageProvider*, unsigned int, unsigned int, unsigned int, unsigned int, void*) + 153220 QuartzCore 0x18a836448 CAImageProviderThread(unsigned int*, bool) + 81221 libdispatch.dylib 0x1861a6a14 _dispatch_client_callout + 1622 libdispatch.dylib 0x1861adbc8 _dispatch_queue_override_invoke$VARIANT$mp + 71623 libdispatch.dylib 0x1861b3cf4 _dispatch_root_queue_drain + 60024 libdispatch.dylib 0x1861b3a38 _dispatch_worker_thread3 + 12025 libsystem_pthread.dylib 0x18644f06c _pthread_wqthread + 126826 libsystem_pthread.dylib 0x18644eb6c start_wqthread + 4There are two threads with this stack trace:#9. com.apple.root.default-qos0 libsystem_kernel.dylib 0x18633c138 __psynch_mutexwait + 81 libsystem_pthread.dylib 0x186453660 _pthread_mutex_lock_wait + 962 libsystem_pthread.dylib 0x1864535a4 _pthread_mutex_lock_slow$VARIANT$mp + 2643 CoreGraphics 0x187fb70ac CGPDFImageCreateImage + 404 CoreGraphics 0x1880256f8 CGPDFDrawingContextDrawImage + 405 CoreGraphics 0x1880de03c op_Do + 1046 CoreGraphics 0x1882e6684 pdf_scanner_handle_xname + 1447 CoreGraphics 0x1882e5f0c CGPDFScannerScan + 3688 CoreGraphics 0x1882f0170 CGPDFDrawingContextDrawPage + 5169 CoreGraphics 0x1880c0a04 pdf_page_draw_in_context + 13210 CoreGraphics 0x187fa763c CGContextDrawPDFPageWithDrawingCallbacks + 7611 CoreGraphics 0x187fa7310 CGContextDrawPDFPage + 3212 myApp 0x1009e8cf0 specialized PDFTiledView.draw(CALayer, in : CGContext) -> () (PDFTiledView.swift:59)13 myApp 0x1009e88ec @objc PDFTiledView.draw(CALayer, in : CGContext) -> () (PDFTiledView.swift)14 QuartzCore 0x18a86b51c -[CALayer drawInContext:] + 29615 QuartzCore 0x18a79c780 tiled_layer_render(_CAImageProvider*, unsigned int, unsigned int, unsigned int, unsigned int, void*) + 153216 QuartzCore 0x18a836448 CAImageProviderThread(unsigned int*, bool) + 81217 libdispatch.dylib 0x1861a6a14 _dispatch_client_callout + 1618 libdispatch.dylib 0x1861adbc8 _dispatch_queue_override_invoke$VARIANT$mp + 71619 libdispatch.dylib 0x1861b3cf4 _dispatch_root_queue_drain + 60020 libdispatch.dylib 0x1861b3a38 _dispatch_worker_thread3 + 12021 libsystem_pthread.dylib 0x18644f06c _pthread_wqthread + 126822 libsystem_pthread.dylib 0x18644eb6c start_wqthread + 4Thanks,Snert
Posted
by Snert.
Last updated
.