- (CGpdfdocumentRef)newSinglePagedocumentFromdocument:(CGpdfdocumentRef)document page:(NSInteger)pageNumber{ CGpdfdocumentRef sourcedocument = CGpdfdocumentRetain(document); CGpdfdocumentRef newdocument = NulL; CFMutableDataRef consumerData = CFDataCreateMutable(kcfAllocatorDefault,0); CGDataConsumerRef contextConsumer = CGDataConsumerCreateWithCFData(consumerData); CGpdfpageRef page = CGpdfdocumentGetPage(sourcedocument,pageNumber); const CGRect mediaBox = CGpdfpageGetBoxRect(page,kCGPdfcropBox); CGContextRef ctx = CGPdfcontextCreate(contextConsumer,&mediaBox,NulL); if (ctx) { if (page) { CGPdfcontextBeginPage(ctx,NulL); CGContextDrawpdfpage(ctx,page); CGPdfcontextEndPage(ctx); } //EXC_BAD_ACCESS thrown here CGPdfcontextClose(ctx); CGContextRelease(ctx); CGDataProvIDerRef provIDer = CGDataProvIDerCreateWithCFData((CFDataRef)consumerData); newdocument = CGpdfdocumentCreateWithProvIDer(provIDer); CGDataProvIDerRelease(provIDer); } CGDataConsumerRelease(contextConsumer); CFRelease(consumerData); CGpdfdocumentRelease(sourcedocument); return newdocument;}
失败的文档可以通过Mac上的预览打开.我无法直观地识别失败的页面和成功的页面之间的任何区别.
任何人都可以看到代码有什么问题,或者发现问题的建议?
编辑:
在CGPdfcontextClose方法中抛出EXC_BAD_ACCESS,如下所示:
0x00e93d0e <+0000> push %ebp0x00e93d0f <+0001> mov %esp,%ebp0x00e93d11 <+0003> sub解决方法 在调试器中设置 NSZombieEnabled,MallocStackLogging和 guard malloc.然后,当您的应用程序崩溃时,在gdb控制台中键入:(gdb) info malloc-history 0x543216x18,%esp0x00e93d14 <+0006> call 0xe93d19 <CGPdfcontextClose+11>0x00e93d19 <+0011> pop %eax0x00e93d1a <+0012> mov 0x8(%ebp),%ecx0x00e93d1d <+0015> test %ecx,%ecx0x00e93d1f <+0017> je 0xe93d30 <CGPdfcontextClose+34>0x00e93d21 <+0019> cmpl x43545854,0x8(%ecx)0x00e93d28 <+0026> jne 0xe93d30 <CGPdfcontextClose+34>0x00e93d2a <+0028> cmpl x1,0x10(%ecx)0x00e93d2e <+0032> je 0xe93d4e <CGPdfcontextClose+64>0x00e93d30 <+0034> mov %ecx,0x8(%esp)0x00e93d34 <+0038> lea 0xc393b(%eax),%ecx0x00e93d3a <+0044> mov %ecx,0x4(%esp)0x00e93d3e <+0048> lea 0xad9eb(%eax),%ecx0x00e93d44 <+0054> mov %ecx,(%esp)0x00e93d47 <+0057> call 0xe7176c <CGPostError>0x00e93d4c <+0062> jmp 0xe93d59 <CGPdfcontextClose+75>0x00e93d4e <+0064> mov 0x18(%ecx),%eax0x00e93d51 <+0067> mov %eax,(%esp)0x00e93d54 <+0070> call 0xdb25af <CGContextDelegateFinalize>0x00e93d59 <+0075> add x18,%esp //EXC_BAD_ACCESS thrown here0x00e93d5c <+0078> pop %ebp0x00e93d5d <+0079> ret
将0x543216替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它可以帮助您查明代码中导致问题的确切行.
See this article for more detailed instructions.
还有一件事是将“Strip DeBUG Symbols”设置为“No”,这样如果您在设备上进行测试,您将能够读取崩溃日志:
总结以上是内存溢出为你收集整理的objective-c – 调用CGPDFContextClose时的EXC_BAD_ACCESS全部内容,希望文章能够帮你解决objective-c – 调用CGPDFContextClose时的EXC_BAD_ACCESS所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)