Hi,
I have reported this issue as a bug already. Still, I'm curious if
there is a way for me to prevent the problem.
I'm rendering a PDF page into an image. Randomly this process crashes
with the stack trace below. The error occurs inside
MonoTouch.CoreGraphics.CGContext.CGContextDrawPDFPage(), so I don't
think there is a way for me to prevent it, but better ask.
I can see the crash in MT 5.2.10 and 5.2.11. I have seen it in the
Simulator only so far. And most interestingly: if it happens, it
happens after the app has just been started (for debugging). If I
restart immediately afterwards and retry, it works. Then I can render
hundreds of pages.
The code:
The page cannot be NULL, that is checked. The CGContext cannot be
NULL, because then SetFillColor() would fail. So I cannot see a
problem in the managed part and hope that somebody sees where in the
unmanaged part the problem is hidden.
public static UIImageView GetLowResPagePreview (CGPDFPage oPdfPage,
RectangleF oTargetRect)
{
var oBackgroundImage =
GetLowResPagePreviewImage(oPdfPage, oTargetRect);
UIImageView oBackgroundImageView = new UIImageView
(oBackgroundImage);
oBackgroundImageView.Frame = new RectangleF (new PointF
(0, 0),
oBackgroundImage.Size);
oBackgroundImageView.ContentMode =
UIViewContentMode.Center;
oBackgroundImageView.UserInteractionEnabled = false;
oBackgroundImageView.AutoresizingMask =
UIViewAutoresizing.None;
return oBackgroundImageView;
}
/// <summary>
/// Gets the low res page preview of a PDF page. Does a quick
image
render of the page.
/// </summary>
/// <param name="iPage">the number of the page to render</param>
/// <param name="oTergetRect">the target rect to fit the PDF
page into</param>
/// <returns>
/// The low res page image view.
/// </returns>
public static UIImage GetLowResPagePreviewImage (CGPDFPage
oPdfPage,
RectangleF oTargetRect)
{
if(oPdfPage == null)
{
return null;
}
RectangleF oPdfPageRect =
PdfViewerHelpers.RotateRectangle(
oPdfPage.GetBoxRect (CGPDFBox.Media), oPdfPage.RotationAngle);
// If preview is requested for the PDF index view,
render a smaller version.
float fAspectScale = 1f;
if (!oTargetRect.IsEmpty)
{
// Resize the PDF page so that it fits the
target rectangle. Also
scale up if it is smaller than the available area.
fAspectScale =
GetAspectZoomFactor(oTargetRect.Size,
oPdfPageRect.Size, true);
oPdfPageRect = new
RectangleF(oPdfPageRect.Location, new
SizeF(oPdfPageRect.Size.Width * fAspectScale, oPdfPageRect.Size.Height
* fAspectScale));
}
int iWidth = Convert.ToInt32 (
Math.Ceiling(oPdfPageRect.Size.Width ));
int iHeight = Convert.ToInt32 (
Math.Ceiling(oPdfPageRect.Size.Height ));
UIImage oBackgroundImage= null;
using(CGColorSpace oColorSpace =
CGColorSpace.CreateDeviceRGB())
{
using(CGBitmapContext oContext = new
CGBitmapContext(null, iWidth,
iHeight, 8, iWidth * 4, oColorSpace,
CGImageAlphaInfo.PremultipliedFirst))
{
// First fill the background with white.
oContext.SetFillColor (1.0f, 1.0f,
1.0f, 1.0f);
oContext.FillRect (oPdfPageRect);
// Apply scale. Cannot use
GetDrawingTransform() because it does
not scale up if the page is smaller than the available area.
oContext.ConcatCTM(
CGAffineTransform.MakeScale(fAspectScale,
fAspectScale));
oContext.InterpolationQuality =
CGInterpolationQuality.Low;
// !!! THIS IS THE LINE WHERE THE CRASH IS HAPPENING !!!
oContext.DrawPDFPage (oPdfPage);
using(CGImage oImage =
oContext.ToImage())
{
oBackgroundImage =
UIImage.FromImage( oImage );
}
}
}
return oBackgroundImage;
}
The Stack trace:
at (wrapper managed-to-native)
MonoTouch.CoreGraphics.CGContext.CGContextDrawPDFPage (intptr,intptr)
<IL 0x00024, 0xffffffff>
at MonoTouch.CoreGraphics.CGContext.DrawPDFPage
(MonoTouch.CoreGraphics.CGPDFPage) [0x00000] in
/Developer/MonoTouch/Source/monotouch/src/shared/CoreGraphics/CGContext.cs:979
at iBrainloop.Controllers.PdfViewer.PdfViewerHelpers.GetLowResPagePreviewImage
(MonoTouch.CoreGraphics.CGPDFPage,System.Drawing.RectangleF) [0x00108]
in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/iBrainloop/Controllers/PdfViewer/PdfViewerHelpers.cs:162
at iBrainloop.Controllers.PdfViewer.PdfViewerHelpers.GetLowResPagePreview
(MonoTouch.CoreGraphics.CGPDFPage,System.Drawing.RectangleF) [0x00000]
in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/iBrainloop/Controllers/PdfViewer/PdfViewerHelpers.cs:111
at
iBrainloop.Controllers.PdfViewer.PdfSinglePageController.RenderHighQualityPdfPage
() [0x00060] in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/iBrainloop/Controllers/PdfViewer/PdfSinglePageController.cs:663
at iBrainloop.Controllers.PdfViewer.PdfSinglePageController.ViewWillAppear
(bool) [0x0003d] in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/iBrainloop/Controllers/PdfViewer/PdfSinglePageController.cs:173
at (wrapper runtime-invoke)
<Module>.runtime_invoke_void__this___sbyte
(object,intptr,intptr,intptr) <IL 0x00054, 0xffffffff>
at (wrapper managed-to-native)
MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr_bool
(intptr,intptr,intptr,bool) <IL 0x0002e, 0xffffffff>
at MonoTouch.UIKit.UIViewController.PresentModalViewController
(MonoTouch.UIKit.UIViewController,bool) [0x00038] in
/Developer/MonoTouch/Source/monotouch/src/UIKit/UIViewController.g.cs:261
at BrainloopMobile.PreviewHelpers/<PreviewLocalDMO>c__AnonStorey21.<>m__52
(BrainloopMobile.ProgressController/PROGRESS_STATUS) [0x00182] in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/BrainloopMobile/Helpers/PreviewHelpers.cs:289
at BrainloopMobile.ProgressController/<DoWork>c__AnonStorey2A.<>m__67
() [0x0002b] in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/BrainloopMobile/Controllers/Progress/ProgressController.cs:316
at MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in
/Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSAction.cs:48
at (wrapper runtime-invoke) object.runtime_invoke_void__this__
(object,intptr,intptr,intptr) <IL 0x0004e, 0xffffffff>
at (wrapper managed-to-native)
MonoTouch.UIKit.UIApplication.UIApplicationMain
(int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string)
[0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at BrainloopMobile.Application.Main (string[]) [0x00000] in
/Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/BrainloopMobile/Main.cs:15
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object
(object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 BrainloopBrowser 0x00094fbc
mono_handle_native_sigsegv + 284
1 BrainloopBrowser 0x0000beb8
mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x99d5c59b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 CoreFoundation 0x960eb468
__CFAllocatorSystemAllocate + 24
5 CoreFoundation 0x960eb444 CFAllocatorAllocate + 356
6 CoreFoundation 0x960eb1a1
_CFRuntimeCreateInstance + 385
7 ImageIO 0x91dc051b _CGImageReadCreate + 83
8 ImageIO 0x91dc0444
CGImageReadCreateWithProvider + 284
9 ImageIO 0x91dc0291
CGImageSourceCreateWithDataProvider + 220
10 CoreGraphics 0x01474ff5
CGImageCreateWithJPEGDataProvider3 + 87
11 CoreGraphics 0x01383ce9 create_image_for_image + 229
12 CoreGraphics 0x01383bd4 CGPDFImageCreateImage + 191
13 CoreGraphics 0x0147135d
CGPDFDrawingContextDrawImage + 34
14 CoreGraphics 0x01377755 op_Do + 115
15 CoreGraphics 0x0146acc9
pdf_scanner_handle_xname + 116
16 CoreGraphics 0x0146b194 CGPDFScannerScan + 216
17 CoreGraphics 0x013a33c4
CGPDFDrawingContextDrawPage + 506
18 CoreGraphics 0x0145e958 pdf_page_draw_in_context + 98
19 CoreGraphics 0x01479c67 CGContextDrawPDFPage + 47
20 ??? 0x1693efa4 0x0 + 378793892
21 ??? 0x1693ef18 0x0 + 378793752
22 ??? 0x1693dbbc 0x0 + 378788796
23 ??? 0x1693d2c4 0x0 + 378786500
24 ??? 0x1693bb24 0x0 + 378780452
25 ??? 0x1693b48c 0x0 + 378778764
26 ??? 0x1693b341 0x0 + 378778433
27 BrainloopBrowser 0x00010222 mono_jit_runtime_invoke + 722
28 BrainloopBrowser 0x00171f6e mono_runtime_invoke + 126
29 BrainloopBrowser 0x00220a62 monotouch_trampoline + 3442
30 UIKit 0x0229a38f -[UIViewController
_setViewAppearState:isAnimating:] + 158
31 UIKit 0x0229a51f
__52-[UIViewController
_setViewAppearState:isAnimating:]_block_invoke_0 + 171
32 CoreFoundation 0x0114c4a5 __NSArrayEnumerate + 597
33 CoreFoundation 0x0114c026 -[NSArray
enumerateObjectsWithOptions:usingBlock:] + 102
34 CoreFoundation 0x0114bf35 -[NSArray
enumerateObjectsUsingBlock:] + 53
35 UIKit 0x0229a44d -[UIViewController
_setViewAppearState:isAnimating:] + 348
36 UIKit 0x0229a51f
__52-[UIViewController
_setViewAppearState:isAnimating:]_block_invoke_0 + 171
37 CoreFoundation 0x0114c4a5 __NSArrayEnumerate + 597
38 CoreFoundation 0x0114c026 -[NSArray
enumerateObjectsWithOptions:usingBlock:] + 102
39 CoreFoundation 0x0114bf35 -[NSArray
enumerateObjectsUsingBlock:] + 53
40 UIKit 0x0229a44d -[UIViewController
_setViewAppearState:isAnimating:] + 348
41 UIKit 0x0229a5eb -[UIViewController
__viewWillAppear:] + 62
42 UIKit 0x0229a893 -[UIViewController
beginAppearanceTransition:animated:] + 203
43 UIKit 0x024b89ba
-[UIWindowController
transition:fromViewController:toViewController:target:didEndSelector:]
+ 5168
44 UIKit 0x0229f857 -[UIViewController
presentViewController:withTransition:completion:] + 3579
45 UIKit 0x0229f9bc -[UIViewController
presentViewController:animated:completion:] + 112
46 UIKit 0x0229f9fc -[UIViewController
presentModalViewController:animated:] + 56
47 ??? 0x134c3771 0x0 + 323762033
48 ??? 0x134c3678 0x0 + 323761784
49 ??? 0x1628aeaf 0x0 + 371764911
50 ??? 0x144ae99a 0x0 + 340453786
51 ??? 0x13fb6b28 0x0 + 335244072
52 ??? 0x09fdea50 0x0 + 167635536
53 BrainloopBrowser 0x00010222 mono_jit_runtime_invoke + 722
54 BrainloopBrowser 0x00171f6e mono_runtime_invoke + 126
55 BrainloopBrowser 0x00220a62 monotouch_trampoline + 3442
56 CoreFoundation 0x011eae42 -[NSObject
performSelector:withObject:] + 66
57 Foundation 0x017649df
__NSThreadPerformPerform + 254
58 CoreFoundation 0x011bd94f
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
59 CoreFoundation 0x01120b43 __CFRunLoopDoSources0 + 243
60 CoreFoundation 0x01120424 __CFRunLoopRun + 1012
61 CoreFoundation 0x0111fd84 CFRunLoopRunSpecific + 212
62 CoreFoundation 0x0111fc9b CFRunLoopRunInMode + 123
63 GraphicsServices 0x047d87d8 GSEventRunModal + 190
64 GraphicsServices 0x047d888a GSEventRun + 103
65 UIKit 0x021d1626 UIApplicationMain + 1163
66 ??? 0x0ede218d 0x0 + 249438605
67 ??? 0x0ede0930 0x0 + 249432368
68 ??? 0x0ede0608 0x0 + 249431560
69 ??? 0x0ede077e 0x0 + 249431934
70 BrainloopBrowser 0x00010222 mono_jit_runtime_invoke + 722
71 BrainloopBrowser 0x00171f6e mono_runtime_invoke + 126
72 BrainloopBrowser 0x00176294 mono_runtime_exec_main + 420
73 BrainloopBrowser 0x00176605 mono_runtime_run_main + 725
74 BrainloopBrowser 0x0006b7f5 mono_jit_exec + 149
75 BrainloopBrowser 0x0022bccc main + 3052
76 BrainloopBrowser 0x00003165 start + 53
René
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch