Post

Replies

Boosts

Views

Activity

Receiving NSMallocException on Real devices while using DrawPDFPage
Hi We're using CGPDFDocument to retrieve the PDF document and draw it in the UIView using CGContext.DrawPDFPage. While doing this operation, I was able to get an NSMallocException with a specific document. I was able to get this exception only on real devices; emulators are working fine. The device used is the iPad (5th generation), which has iOS 16.7.8. Steps to replicate: Open the application at the link (we have attached the sample with PDF file with the issue in the link) https://www.dropbox.com/scl/fi/mosvcnqc0nvxwdjf8k0m5/SimplePDFVieweriOS.zip?rlkey=0ntj75yjg71kjwtwwe06uax5v&st=mmv08e2f&dl=0 Navigate through the pages using the next button. After the page navigation to page 7, and the application will throw an NSMallocException with the reason: Failed to grow buffer Platform: Xamarin.iOS Development tool: Visual Studio 2022 Stack trace for the issue: Native stack trace: 0 CoreFoundation 0x00000001b32e9418 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 37912 1 libobjc.A.dylib 0x00000001ac63dc28 objc_exception_throw + 56 2 CoreFoundation 0x00000001b347c5c8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1689032 3 CoreFoundation 0x00000001b3474504 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1656068 4 CoreFoundation 0x00000001b3363160 __CFSafelyReallocate + 68 5 CoreFoundation 0x00000001b33aae9c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 831132 6 CoreFoundation 0x00000001b335af2c CFDataSetLength + 152 7 CoreGraphics 0x00000001b4ca71a4 CGDataProviderCopyData + 240 8 ImageIO 0x00000001b7fafd38 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 32056 9 ImageIO 0x00000001b7fb1124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 37156 10 ImageIO 0x00000001b7ff7124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 323876 11 ImageIO 0x00000001b7fb0fe0 CGImageSourceCreateWithDataProvider + 176 12 CoreGraphics 0x00000001b4d7ac0c EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1018892 13 CoreGraphics 0x00000001b4d7a9a0 CGPDFImageCreateImage + 208 14 CoreGraphics 0x00000001b4decbc8 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1485768 15 CoreGraphics 0x00000001b4d26e34 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 675380 16 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 17 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 18 CoreGraphics 0x00000001b5073198 CGPDFDrawingContextDraw + 112 19 CoreGraphics 0x00000001b4d271b0 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 676272 20 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 21 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 22 CoreGraphics 0x00000001b4d3f68c CGContextDrawPDFPageWithDrawingCallbacks + 2680 23 CoreGraphics 0x00000001b4cdb04c CGContextDrawPDFPage + 32 24 SimplePDFViewer 0x0000000100f0cb90 SimplePDFViewer + 1969040 25 SimplePDFViewer 0x0000000100eeb3c0 SimplePDFViewer + 1831872 26 SimplePDFViewer 0x0000000100d35b14 SimplePDFViewer + 39700 27 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 28 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 29 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 30 SimplePDFViewer 0x0000000100fdc014 mono_pmip + 630308 31 SimplePDFViewer 0x0000000100d32450 SimplePDFViewer + 25680 32 SimplePDFViewer 0x0000000100d32328 SimplePDFViewer + 25384 33 UIKitCore 0x00000001b5412150 27A9C298-B702-3C39-8C06-07196E4CD16B + 1667408 34 QuartzCore 0x00000001b47990e8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 119016 35 QuartzCore 0x00000001b480adb8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 585144 36 QuartzCore 0x00000001b47987a8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 116648 37 QuartzCore 0x00000001b4798034 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 114740 38 QuartzCore 0x00000001b47a89f0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 182768 39 QuartzCore 0x00000001b47d5dc0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 368064 40 QuartzCore 0x00000001b47c0dc8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 282056 41 CoreFoundation 0x00000001b33698e8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 563432 42 CoreFoundation 0x00000001b32f951c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 103708 43 CoreFoundation 0x00000001b3355214 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 479764 44 CoreFoundation 0x00000001b3359d20 CFRunLoopRunSpecific + 584 45 GraphicsServices 0x00000001eab69998 GSEventRunModal + 160 46 UIKitCore 0x00000001b55ec448 27A9C298-B702-3C39-8C06-07196E4CD16B + 3609672 47 UIKitCore 0x00000001b55ec0c0 UIApplicationMain + 312 48 SimplePDFViewer 0x000000010106b350 xamarin_UIApplicationMain + 60 49 SimplePDFViewer 0x0000000100f0de18 SimplePDFViewer + 1973784 50 SimplePDFViewer 0x0000000100eecd4c SimplePDFViewer + 1838412 51 SimplePDFViewer 0x0000000100eece70 SimplePDFViewer + 1838704 52 SimplePDFViewer 0x0000000100d33ad0 SimplePDFViewer + 31440 53 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 54 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 55 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 56 SimplePDFViewer 0x0000000100fddbdc mono_pmip + 637420 57 SimplePDFViewer 0x0000000100f2d5ec SimplePDFViewer + 2102764 58 SimplePDFViewer 0x00000001010802dc xamarin_log + 22464 59 SimplePDFViewer 0x0000000100d334bc SimplePDFViewer + 29884 60 dyld 0x00000001d0b04344 8A4B89B7-D348-375B-97B1-FC8A84E3E5CE + 82756 Kindly let us know if you need any further details regarding this issue.
0
0
263
Aug ’24
The application crashes when an image of a certain PDF (50 MB, 1 page) is drawn on the context page in background.
Hi Team, I am using CGPDFPage and CGContext to convert the PDF to an image. It is working fine in all circumstances but fails in one circumstance where the size of the PDF is above 50 MB and when the application is made to be on background and again opened. It is also occurring only on physical devices; emulators are working fine. We are using the following code for this conversation: fileStream.CopyTo(memoryStream); CGDataProvider provider = new CGDataProvider(memoryStream.ToArray()); CGPDFDocument cGPDFDocument = null; image = null; cGPDFDocument = new CGPDFDocument(provider); using(CGPDFPage pdfPage = cGPDFDocument?.GetPage(1)) { if (pdfPage != null) { CGRect rect = pdfPage.GetBoxRect(CGPDFBox.Media); if (pdfPage.RotationAngle == 90 || pdfPage.RotationAngle == 270) { rect = new CGRect(rect.X, rect.Y, rect.Height, rect.Width); } nfloat factor = (nfloat)0.5; CGRect bounds = new CGRect(rect.X * factor, rect.Y * factor, rect.Width * factor, rect.Height * factor); UIGraphics.BeginImageContext(bounds.Size); CGContext context = UIGraphics.GetCurrentContext(); context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f); context.FillRect(bounds); context.TranslateCTM(0, bounds.Height); context.ScaleCTM(factor, -factor); context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true)); context.SetRenderingIntent(CGColorRenderingIntent.Default); context.InterpolationQuality = CGInterpolationQuality.Default; context.DrawPDFPage(pdfPage); image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); imageView.Image = image; parentView.AddSubview(imageView); } } We have added a simple application created on Xamarin.iOS platform that replicates this issue in Assets we have added the PDF with this issue https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfToImageSample-556012354 We have recorded this for the reference, https://www.syncfusion.com/downloads/support/directtrac/general/ze/CrashBGImgRec-1376481150 This issue is constantly occurring on the "context.DrawPDFPage(pdfPage);" line in my application. On the provided sample, this issue is occurring consistently when the break point is placed on the "context.DrawPDFPage(pdfPage);" line. It also occurs randomly without placing the breakpoint. We are invoking this function on DidEnterBackground override method of AppDelegate Do we need to set any to properly retrieve the image from CGPDFPage and add them into context?
1
0
457
Jun ’24
Image quality decreases while saving UIImage
We are creating a PDF viewer application fin the Xamarin platform. In that, we are adding a stamp annotation, which is added as a UIImage. While saving this UIImage, there is a loss in the quality of the image annotation. I have attached the example code below that causes the issue. Is there any way to improve the quality of the UIImage that we get from UIImageView? I have attached an image that has been changed from 36kb to 18kb. The image is more pixelated than the initial image. Assembly assembly = Assembly.Load(new AsemblyName("Syncfusion.SfPdfViewer.XForms.iOS")); Stream stream = assembly.GetManifestResourceStream(string.Format("<path>.screen-shot.png")); var imagedata = NSData.FromStream(stream); if (imagedata != null) { image = UIImage.LoadFromData(imagedata); } UIImageView imageView1 = new UIImageView(image); imageView1.Frame = imageView.Bounds; var UiImageTest=ConvertToImage(imageView1); using(var imageStream=UiImageTest.AsPNG().AsStream()) { string path = "/Users/<path on MAC>"; string filepath = System.IO.Path.Combine(path, "StampParserTestjpegSave.png"); FileStream outputFileStream = File.Open(filepath, FileMode.Create); imageStream.Position = 0; imageStream.CopyTo(outputFileStream); outputFileStream.Close(); } private UIImage ConvertToImage(UIView view) { if (UIDevice.CurrentDevice != null && UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { var format = new UIGraphicsImageRendererFormat(); format.Scale = UIScreen.MainScreen.Scale; var renderer = new UIGraphicsImageRenderer(view.Bounds.Size, format); return renderer.CreateImage((rendererContext) => { view.Layer.RenderInContext(rendererContext.CGContext); }); } else { UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, 0); view.Opaque = false; view.DrawViewHierarchy(view.Bounds, true); view.Layer.RenderInContext(UIGraphics.GetCurrentContext()); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return img; } }
3
0
589
Aug ’23