UIGraphicsBeginPDFPage()在64位设备上随机崩溃(CGPDFSecurityManagerCreateDecryptor())

我正在努力使用PDF导出方法,直到我将应用程序移植到arm64架构。

Bacisally,该方法打开一个现有的PDF,它创build一个新的PDF文件,并绘制第一个PDF的内容到新创build的一个,然后添加更多的内容页面。

当该方法尝试创build一个新的pdf页面到文档(在第一个pdf被集成到新的pdf之后),该应用程序在UIGraphicsBeginPDFPage()上出现EXC_BAD_ACCESS警告。 打电话。

它只发生在一些PDF文件,不是所有的,只在64位设备上。

下面是显示CGPDFSecurityManagerCreateDecryptor()调用的堆栈跟踪,我找不到它的function。

Thread 14Queue : NSOperationQueue 0x14f6dd3a0 :: NSOperation 0x17504a470 (serial) #0 0x00000001838aeee4 in CGPDFSecurityManagerCreateDecryptor () #1 0x00000001838d1004 in pdf_filter_chain_create () #2 0x0000000183831e00 in CGPDFStreamCreateFilterChain () #3 0x000000018383226c in chain_get_bytes () #4 0x0000000183b5e0ac in unpackImageRow () #5 0x0000000183b5dfd4 in PDFImageEmitData () #6 0x0000000183b5f684 in emit_image () #7 0x0000000183b5ef9c in PDFImageEmitDefinition () #8 0x0000000183464584 in __CFSetApplyFunction_block_invoke () #9 0x00000001834643bc in CFBasicHashApply () #10 0x00000001834642e4 in CFSetApplyFunction () #11 0x0000000183b5fa9c in PDFImageSetEmitDefinitions () #12 0x0000000183b590c0 in emit_page_resources(PDFDocument*) () #13 0x0000000183b5904c in PDFDocumentEndPage () #14 0x0000000183b57cf0 in pdf_EndPage () #15 0x0000000187fda904 in UIGraphicsBeginPDFPageWithInfo () #16 0x00000001002093e8 in -[ExportTools renderPdfContentToContext:forPlanVersion:] #17 0x00000001001fba60 in -[ExportTools generatePdfReportWithOptions:] #18 0x00000001000f7eb4 in -[DetailViewController generatePdfAndShowModalOpenWithAppWithOptions:] #19 0x00000001835883c0 in __invoking___ () #20 0x0000000183486138 in -[NSInvocation invoke] () #21 0x000000018443ba20 in -[NSInvocationOperation main] () #22 0x000000018437c61c in -[__NSOperationInternal _start:] () #23 0x000000018443e26c in __NSOQSchedule_f () #24 0x000000010105cdf0 in _dispatch_client_callout () #25 0x0000000101067854 in _dispatch_queue_drain () #26 0x0000000101060120 in _dispatch_queue_invoke () #27 0x000000010106975c in _dispatch_root_queue_drain () #28 0x000000010106af18 in _dispatch_worker_thread3 () #29 0x00000001945012e4 in _pthread_wqthread () 

如果你对这次崩溃有任何的想法,你的帮助将不胜感激,总有一天试图解决这个问题,并怀疑它是不是一个UIKit错误…

谢谢

我在64位设备上的CGPDFSecurityManagerCreateDecryptor方法只有下面的代码崩溃:

 CGPDFDocumentRelease(pdf); CGDataProviderRelease(provider); UIGraphicsEndPDFContext(); 

CGPDFSecurityManagerCreateDecryptor将在结束上下文时被调用。 当我在发布文档和提供者之前结束上下文时,崩溃消失了。

 UIGraphicsEndPDFContext(); CGPDFDocumentRelease(pdf); CGDataProviderRelease(provider); 

我一直在同样的问题上挣扎,而比尔的回答给了我线索,我不得不做一点点不同。 在我的情况下,有不定数量的源PDF被复制到目标PDF中,所以我不能简单地在UIGraphicsEndContext之前移动UIGraphicsEndContext 。 代码结构大致如下所示:

 UIGraphicsBeginPDFContextToFile(...); // ... for each attachment pdf { srcPdf = CGPDFDocumentCreateWithURL(...); // open source PDF // ... UIGraphicsBeginPDFPageWithInfo(...); // new page in target PDF, this randomly crashes // ... CGPDFDocumentRelease(srcPdf); // close source PDF } // ... UIGraphicsEndPDFContext(); 

因此,我尝试捕获所使用的所有源代码PDF的引用,并在目标PDF的其余部分完成后释放它们,稍后在代码中完成。 这是一种丑陋,因为它将责任推到很远的地方,把所有的记忆都保存到最后,而不是在每一个呈现之后都释放出来,但是它似乎工作起来了! 这是很难说,因为它是一个随机的崩溃,但我没有看到它,因为我一直在努力试图重新锤击它。

 pdfRefs = [[NSPointerArray alloc] init]; UIGraphicsBeginPDFContextToFile(...); // ... for each attachment pdf { srcPdf = CGPDFDocumentCreateWithURL(...); // open source PDF // ... UIGraphicsBeginPDFPageWithInfo(...); // new page in target PDF, this randomly crashes // ... [pdfRefs addPointer:srcPdf]; // store for later closing } // ... UIGraphicsEndPDFContext(); for each srcPdf in pdfRefs { CGPDFDocumentRelease(srcPdf); // close it here }