【问题标题】:UIGraphicsBeginPDFPage() randomly crashes on 64bit devices (CGPDFSecurityManagerCreateDecryptor ())UIGraphicsBeginPDFPage() 在 64 位设备上随机崩溃 (CGPDFSecurityManagerCreateDecryptor ())
【发布时间】:2015-02-18 19:10:01
【问题描述】:

在我将应用程序移植到 arm64 架构之前,我一直在努力使用运行良好的 pdf 导出方法。

基本上,该方法打开一个现有的 PDF,它创建一个新的 pdf 文件,并在添加更多内容页面之前将第一个 pdf 的内容绘制到新创建的文件中。

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

它只发生在一些 PDF 文件上,而不是全部,而且只发生在 64 位设备上。

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

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 错误...

谢谢

【问题讨论】:

  • 我在同一个函数中看到了同样的崩溃,但堆栈跟踪不同。虽然我没有编写有问题的软件,但我可以验证它也可以处理 PDF 文档并在 OS X 10.10 上运行,因此它是 64 位

标签: ios pdf uikit quartz-2d cgpdf


【解决方案1】:

我也一直在为同样的问题而苦苦挣扎,虽然比尔的回答给了我线索,但我必须采取一些不同的做法。在我的情况下,有数量不定的源 PDF 被复制到目标 PDF 中,所以我不能简单地将 UIGraphicsEndContext 移动到 CGPDFDocumentRelease 之前。代码结构大致如下:

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
}

【讨论】:

    【解决方案2】:

    我在 64 台设备上的 CGPDFSecurityManagerCreateDecryptor 方法崩溃了,代码如下:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 2014-03-23
      相关资源
      最近更新 更多