UIImage-PDF
UIImage-PDF copied to clipboard
Crashes on CGContextDrawPDFPage( ctx, page1 );
Hi!
Firstly, Thanks for this amazing library! On iOS 8 app crahes on CGContextDrawPDFPage( ctx, page1 ); when i try to load Pdf into Image. I have tried different pdf files.
Please help!
Hi Azkaar. Thanks for the report. Can you give me a an Xcode backtrace?
Hi Azkaar. I've made some code updates. Does it still crash?
Hi @mindbrix . Sorry for late reply, I was away.
Unfortunately fix didn't work for me. Attached an Xcode backtrace.
Please, look into this.
Thanks!
Hi @AzkaarAli, thanks for the back trace. The crash is in the Core Graphics PDF font loading code. Does the PDF render using Quick Look? Where did the PDF come from?
same crash on CGContextDrawPDFPage( ctx, page1 );
Same crash for me,
(lldb) po ctx
<CGContext 0x17016fd80>
(lldb) po page1
error: Couldn't materialize: couldn't get the value of variable page1: read memory from 0x38 failed (0 of 8 bytes read)
Errored out in Execute, couldn't PrepareToExecuteJITExpression
Printing description of mediaRect:
(CGRect) mediaRect = (origin = (x = <read memory from 0x18 failed (0 of 8 bytes read)>, y = <read memory from 0x20 failed (0 of 8 bytes read)>), size = (width = <read memory from 0x28 failed (0 of 8 bytes read)>, height = <read memory from 0x30 failed (0 of 8 bytes read)>))
Message from debugger: failed to send the k packet
This happens in very strange situations. Everything works okay, while I didn't reinstall app, after reinstall - ONLY this pdf file become corrupted.
pdf file - http://s.oks.im//newsfeed-btn.pdf
backtrace:
* thread #1: tid = 0xd07f, 0x0000000195ac13f0 libc++abi.dylib`__cxa_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000195ac13f0 libc++abi.dylib`__cxa_throw
frame #1: 0x000000018d0bcd40 libFontParser.dylib`TcmapEncodingTable::GetSubtable(unsigned short, unsigned short, unsigned short, unsigned short*) + 544
frame #2: 0x000000018d0cef00 libFontParser.dylib`TcmapEncodingTable::TcmapEncodingTable(TSFNTFont const&, unsigned short, unsigned short, unsigned short) + 116
frame #3: 0x000000018d0e8170 libFontParser.dylib`FPFontGetTrueTypeEncoding + 144
frame #4: 0x0000000184e9dce4 libCGXType.A.dylib`get_truetype_encoding + 72
frame #5: 0x0000000184d4eff8 CoreGraphics`CGFontGetTrueTypeEncoding + 28
frame #6: 0x0000000184d79b98 CoreGraphics`lookup_glyphs_by_cmap_nonsymbolic + 224
frame #7: 0x0000000184d79970 CoreGraphics`lookup_glyphs_by_cmap + 104
frame #8: 0x0000000184d78fac CoreGraphics`get_truetype_glyph_vector + 260
frame #9: 0x0000000184d78d70 CoreGraphics`CGPDFEncodingGetGlyphVector + 160
frame #10: 0x0000000184e01bb0 CoreGraphics`simple_draw + 156
frame #11: 0x0000000184e01920 CoreGraphics`CGPDFTextLayoutDrawGlyphs + 112
frame #12: 0x0000000184dff7c4 CoreGraphics`op_Tj + 72
frame #13: 0x0000000184d77364 CoreGraphics`pdf_scanner_handle_xname + 116
frame #14: 0x0000000184d76bd0 CoreGraphics`CGPDFScannerScan + 272
frame #15: 0x0000000184df9754 CoreGraphics`CGPDFDrawingContextDrawPage + 440
frame #16: 0x0000000184dfd328 CoreGraphics`pdf_page_draw_in_context + 108
frame #17: 0x0000000184d5c6b4 CoreGraphics`CGContextDrawPDFPage + 48
* frame #18: 0x000000010015fa68 ShipMate`+[PDFView renderIntoContext:url:data:size:page:](self=0x0000000100bdf160, _cmd=0x000000010094ef85, ctx=0x000000017417e540, resourceURL=0x00000001704b1100, resourceData=0x0000000000000000, size=(width = 302, height = 53), page=1) + 288 at PDFView.m:167
frame #19: 0x000000010034fd9c ShipMate`+[UIImage(self=0x0000000197bc26c0, _cmd=0x00000001009604e2, URL=0x00000001704b1100, size=(width = 302, height = 53), page=1) imageWithPDFURL:atSize:atPage:] + 888 at UIImage+PDF.m:315
frame #20: 0x000000010035049c ShipMate`+[UIImage(self=0x0000000197bc26c0, _cmd=0x0000000100960552, URL=0x00000001704b1100, height=53, page=1) imageWithPDFURL:atHeight:atPage:] + 248 at UIImage+PDF.m:397
frame #21: 0x0000000100350534 ShipMate`+[UIImage(self=0x0000000197bc26c0, _cmd=0x0000000100960573, URL=0x00000001704b1100, height=53) imageWithPDFURL:atHeight:] + 104 at UIImage+PDF.m:402
frame #22: 0x000000010034eb28 ShipMate`+[UIImage(self=0x0000000197bc26c0, _cmd=0x0000000100942922, resourceName=0x0000000100a454f0, height=53) imageWithPDFNamed:atHeight:] + 136 at UIImage+PDF.m:155
frame #23: 0x0000000100280b24 ShipMate`-[HomePageViewController viewDidLoad](self=0x00000001375a3c00, _cmd=0x0000000189cf4be0) + 5780 at HomePageViewController.m:421
frame #24: 0x00000001894ecc84 UIKit`-[UIViewController loadViewIfRequired] + 692
frame #25: 0x00000001895a2f68 UIKit`-[UINavigationController _layoutViewController:] + 64
frame #26: 0x00000001895a2e64 UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 248
frame #27: 0x00000001895a22f0 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 112
frame #28: 0x00000001895a1f9c UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 640
frame #29: 0x00000001895a1cbc UIKit`-[UINavigationController __viewWillLayoutSubviews] + 56
frame #30: 0x00000001895a1c3c UIKit`-[UILayoutContainerView layoutSubviews] + 200
frame #31: 0x00000001894e9760 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 580
frame #32: 0x0000000188e31e1c QuartzCore`-[CALayer layoutSublayers] + 152
frame #33: 0x0000000188e2c884 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 320
frame #34: 0x0000000188e2c728 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
frame #35: 0x0000000188e2bebc QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 276
frame #36: 0x0000000188e2bc3c QuartzCore`CA::Transaction::commit() + 528
frame #37: 0x0000000189778838 UIKit`-[UIApplication _reportMainSceneUpdateFinished:] + 60
frame #38: 0x000000018977971c UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 2804
frame #39: 0x0000000189777778 UIKit`-[UIApplication workspaceDidEndTransaction:] + 184
frame #40: 0x000000018d2b53c8 FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke_2 + 32
frame #41: 0x0000000184a6427c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
frame #42: 0x0000000184a63384 CoreFoundation`__CFRunLoopDoBlocks + 312
frame #43: 0x0000000184a619a8 CoreFoundation`__CFRunLoopRun + 1756
frame #44: 0x000000018498d2d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #45: 0x000000018955843c UIKit`-[UIApplication _run] + 552
frame #46: 0x0000000189552fac UIKit`UIApplicationMain + 1488
frame #47: 0x000000010013acd8 ShipMate`main(argc=1, argv=0x000000016fdd79d8) + 124 at main.m:15
frame #48: 0x0000000196956a08 libdyld.dylib`start + 4
Hi. It's crashing when looking up the font glyphs to render. Does it crash in the same place each time?
yep, same place, same time :)
+1
The crashes are deep in CG PDF code, so I would recommend filing a Radar with Apple with a sample project that reproduces the issue.
It could be a PDF file format issue. Try running the PDF through ShrinkIt: https://panic.com/blog/shrinkit-1-0/ to see if that helps.