Bug 312 - showing UIDocumentInteractionController crashes the App
Summary: showing UIDocumentInteractionController crashes the App
Status: CLOSED DUPLICATE of bug 265
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 4.x
Hardware: Macintosh Mac OS
: High blocker
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on: 265
  Show dependency tree
Reported: 2011-08-17 09:37 UTC by Marco
Modified: 2012-01-04 12:20 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

PdfAppTest Solution (1.30 MB, application/x-zip-compressed)
2011-08-17 10:36 UTC, Marco
pdf document using during the test (6.22 KB, application/pdf)
2011-08-17 10:36 UTC, Marco

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marco 2011-08-17 09:37:31 UTC
I have made a application to show a PDF document; I created a new project with a View and I placed a  button with a single action:

The document is shown for a few milliseconds and then the application crashes

partial void Button1_Pressed(UIButton sender)
    String s = “MyPdffile.PDF”
    NSUrl ns = NSUrl.FromFilename(s); 
    UIDocumentInteractionController PreviewController = UIDocumentInteractionController.FromUrl(ns); 
    PreviewController.Delegate = new MxUIDocumentInteractionControllerDelegateClass(this); 

Here below the delegate class:

    public class MxUIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate 
       private UIViewController mViewController; 

    public MxUIDocumentInteractionControllerDelegateClass(UIViewController viewController) 
        mViewController = viewController; 

    public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller) 
        return mViewController; 

    public override UIView ViewForPreview (UIDocumentInteractionController controller) 
        return mViewController.View; 

    public override RectangleF RectangleForPreview (UIDocumentInteractionController controller) 
        return mViewController.View.Frame; 

    public override void DidEndPreview (UIDocumentInteractionController controller) 
       Console.WriteLine ("DidEndPreview "); 
//never execute

    public override void WillBeginPreview (UIDocumentInteractionController controller) 

This is the output message:

  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
  at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x0002a] in /Developer/MonoTouch/Source/monotouch/monotouch/Foundation/NSObject.cs:305 
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 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) [0x00038] in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:26 
  at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:31 
  at MxMobile.iOS.Application.Main (string[]) [0x00000] in /Users/Test/Projects/MyApp/dev/iPad/Application/Main.cs:16 
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace: 
        0   MyApp                        0x000d0de8 mono_handle_native_sigsegv + 343 
        1   MyApp                        0x0000f74c mono_sigsegv_signal_handler + 322 
        2   libSystem.B.dylib                   0x905e445b _sigtramp + 43 
        3   ???                                 0xffffffff 0x0 + 4294967295 
        4   ???                                 0x0e35247c 0x0 + 238363772 
        5   ???                                 0x07ee8196 0x0 + 133071254 
        6   MyApp                        0x0000f507 mono_jit_runtime_invoke + 1332 
        7   MyApp                        0x001ed259 mono_runtime_invoke + 137 
        8   MyApp                        0x0029d91f monotouch_trampoline + 2527 
        9   Foundation                          0x0137f9a6 __NSThreadPerformPerform + 251 
        10  CoreFoundation                      0x00e2301f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
        11  CoreFoundation                      0x00d8128b __CFRunLoopDoSources0 + 571 
        12  CoreFoundation                      0x00d80786 __CFRunLoopRun + 470 
        13  CoreFoundation                      0x00d80240 CFRunLoopRunSpecific + 208 
        14  CoreFoundation                      0x00d80161 CFRunLoopRunInMode + 97 
        15  GraphicsServices                    0x03ee0268 GSEventRunModal + 217 
        16  GraphicsServices                    0x03ee032d GSEventRun + 115 
        17  UIKit                               0x01c1a42e UIApplicationMain + 1160 
        18  ???                                 0x07fa9dcb 0x0 + 133864907 
        19  ???                                 0x07fa9b9c 0x0 + 133864348 
        20  ???                                 0x07fa919c 0x0 + 133861788 
        21  ???                                 0x07fa8ff4 0x0 + 133861364 
        22  ???                                 0x07fa9146 0x0 + 133861702 
        23  MyApp                        0x0000f507 mono_jit_runtime_invoke + 1332 
        24  MyApp                        0x001ed259 mono_runtime_invoke + 137 
        25  MyApp                        0x001ef940 mono_runtime_exec_main + 669 
        26  MyApp                        0x001eed2a mono_runtime_run_main + 843 
        27  MyApp                        0x000a3093 mono_jit_exec + 200 
        28  MyApp                        0x002a163d main + 4060 
        29  MyApp                        0x00002819 _start + 208 
        30  MyApp                        0x00002748 start + 40 
        31  ???                                 0x00000002 0x0 + 2
Comment 1 Sebastien Pouliot 2011-08-17 09:47:24 UTC
It looks like your UIDocumentInteractionController, being a local variable, is getting collected by the GC while the iOS native code will still use it via the delegate. Try to move the local into a instance field.

If that does not work then please attach a self-contained test case, including the .pdf you're using and we'll try to duplicate the issue. Thanks!
Comment 2 Marco 2011-08-17 10:36:17 UTC
Created attachment 149 [details]
PdfAppTest Solution
Comment 3 Marco 2011-08-17 10:36:44 UTC
Created attachment 150 [details]
pdf document using during the test
Comment 4 Marco 2011-08-17 10:37:17 UTC
A tried to move the UIDocumentInteractionController in global variables, but we're still having problem.

I attached the solution and the pdf documents that we're using

Let me know
Comment 5 Sebastien Pouliot 2011-08-17 15:27:15 UTC
I can duplicate the issue. Thanks for the sample.
Comment 6 Sebastien Pouliot 2011-08-18 10:14:53 UTC
Something weird is going on. The UIDocumentInteractionController Handle is broken when RectangleForPreview is called. Since this is an override of a method returning a struct then I think it's related to ABI bug #265

Handle 181131264
ViewControllerForPreview 181131264
ViewForPreview 181131264
RectangleForPreview -1073755696
WillBeginPreview 181131264
'/Users/sebastienpouliot/Library/Application Support/iPhone Simulator/4.3.2/Applications/82FFC89F-CBA9-4C16-B4D1-47105EEBB57A/PdfAppTest.app/Read.pdf' loaded

  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
Comment 7 Sebastien Pouliot 2011-08-18 10:18:29 UTC
Yes. If you remove the RectangleForPreview override then everything works fine.

Marking the bug as a duplicate of #265. The workaround is to add a #define around the override to exclude it in the sumlator.

Note: the ABI issue exists only on the simulator, you can still use the code when deploying to devices.

*** This bug has been marked as a duplicate of bug 265 ***
Comment 8 Marco 2011-08-18 10:33:51 UTC
Ok, removing RectangleForPreview override solved the problem. Thank you!
Comment 9 lindsey.driscoll 2012-01-04 12:20:34 UTC
Closing duplicates