A DialogViewController with RefreshRequested and E

2019-08-10 20:36发布

问题:

A DialogViewController contains an EntryElement and RefreshRequested handler is set (see code below). Run in the simulator, debug mode, type some quick random text (containing spaces) in the EntryElement. Crash will follow.

What I am doing wrong ?

I guess this is a bug in DialogViewController not retaining some images that is garbage collected. Is there a switch to trace garbage collector and removed objects ?

the offending code :

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
    // class-level declarations
    UIWindow window;
    UINavigationController navController;
    DialogViewController dv ;


    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        // create a new window instance based on the screen size
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        navController = new UINavigationController();
        var root = new RootElement("Test") {
            new Section("Quick type some text") {
                new EntryElement("that contains spaces", string.Empty, string.Empty)
            }
        };

        dv = new DialogViewController(root, true);
        dv.RefreshRequested += HandleDvRefreshRequested; // comment this line fixes the bug
        window.MakeKeyAndVisible ();


        if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0)) {
            window.RootViewController = navController;
        } else {
            window.AddSubview (navController.View);
        }

        return true;
    }

    void HandleDvRefreshRequested (object sender, EventArgs e)
    {
       dv.ReloadComplete();
    }
}

   Starting iOS simulator 5.0
   Launching application
   Application launched. PID = 4730
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll [External]
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll [External]
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.dll [External]
   Thread started: 
   Loaded assembly: /Users/user/Documents/iphone-cinetoile/Cinetoile.UI2/bin/iPhoneSimulator/Debug/MyApp.exe
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.Dialog-1.dll [External]
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll [External]
   Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll [External]

Stacktrace:

  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) 
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
  at MyApp.Application.Main (string[]) [0x00000] in /Users/user/Documents/MyApp/Main.cs:17
  at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr) 

Native stacktrace:

0   MyApp                               0x000908ec mono_handle_native_sigsegv + 284
1   MyApp                               0x00005c88 mono_sigsegv_signal_handler + 248
2   libSystem.B.dylib                   0x9141905b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   ???                                 0x92c013ef 0x0 + 2462061551
5   ???                                 0x92c011ee 0x0 + 2462061038
6   ???                                 0x987a313c 0x0 + 2558144828
7   CoreGraphics                        0x91b49e20 CGDataProviderRetain + 22
8   ???                                 0x9880c456 0x0 + 2558575702
9   ImageIO                             0x9754a0d2 CGImageReadCreateWithProvider + 185
10  ImageIO                             0x97549fee CGImageSourceCreateWithDataProvider + 186
11  CoreGraphics                        0x013c0d2f CGImageCreateWithPNGDataProvider + 87
12  WebCore                             0x073ca2a5 WKGraphicsCreateImageFromBundleWithName + 373
13  WebCore                             0x06c1c5bd _ZN7WebCore15GraphicsContext23drawLineForTextCheckingERKNS_10FloatPointEfNS0_21TextCheckingLineStyleE + 369
14  WebCore                             0x06cf6e84 _ZN7WebCore13InlineTextBox28paintSpellingOrGrammarMarkerEPNS_15GraphicsContextERKNS_10FloatPointERKNS_14DocumentMarkerEPNS_11RenderStyleERKNS_4FontEb + 1684
15  WebCore                             0x06cf6fb9 _ZN7WebCore13InlineTextBox20paintDocumentMarkersEPNS_15GraphicsContextERKNS_10FloatPointEPNS_11RenderStyleERKNS_4FontEb + 297
16  WebCore                             0x06cf33fc _ZN7WebCore13InlineTextBox5paintERNS_9PaintInfoEiiii + 6490
17  WebCore                             0x06cec3cd _ZN7WebCore13InlineFlowBox5paintERNS_9PaintInfoEiiii + 1065
18  WebCore                             0x0724d24c _ZN7WebCore13RootInlineBox5paintERNS_9PaintInfoEiiii + 64
19  WebCore                             0x071a8e2a _ZNK7WebCore17RenderLineBoxList5paintEPNS_20RenderBoxModelObjectERNS_9PaintInfoEii + 638
20  WebCore                             0x07142089 _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 369
21  WebCore                             0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
22  WebCore                             0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
23  WebCore                             0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
24  WebCore                             0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
25  WebCore                             0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
26  WebCore                             0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
27  WebCore                             0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
28  WebCore                             0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
29  WebCore                             0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
30  WebCore                             0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
31  WebCore                             0x071961b0 _ZN7WebCore11RenderLayer10paintLayerEPS0_PNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectEPN3WTF7HashMapIPNS_24OverlapTestRequestClientES4_NS9_7PtrHashISC_EENS9_10HashTraitsISC_EENSF_IS4_EEEEj + 3684
32  WebCore                             0x0719648c _ZN7WebCore11RenderLayer10paintLayerEPS0_PNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectEPN3WTF7HashMapIPNS_24OverlapTestRequestClientES4_NS9_7PtrHashISC_EENS9_10HashTraitsISC_EENSF_IS4_EEEEj + 4416
33  WebCore                             0x071973bb _ZN7WebCore11RenderLayer5paintEPNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectE + 101
34  WebCore                             0x06bef809 _ZN7WebCore9FrameView13paintContentsEPNS_15GraphicsContextERKNS_7IntRectE + 591
35  WebKit                              0x067a51d0 -[WebFrame(WebInternal) _drawRect:contentsOnly:] + 368
36  WebKit                              0x067cc83c -[WebHTMLView drawSingleRect:] + 124
37  WebKit                              0x067cc786 -[WebHTMLView drawRect:] + 118
38  WebCore                             0x07392c2f _ZL12drawCallbackP6WKView6CGRectPv + 95
39  WebCore                             0x073cd52c _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 492
40  WebCore                             0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
41  WebCore                             0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
42  WebCore                             0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
43  WebCore                             0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
44  WebCore                             0x073cd80e WKViewDisplayRect + 158
45  WebCore                             0x073cead0 WKWindowDrawRect + 48
46  WebCore                             0x0735daf0 _ZN7WebCore9TileCache9drawLayerEP9TileLayerP9CGContext + 880
47  WebCore                             0x07362af1 -[TileLayer drawInContext:] + 49
48  QuartzCore                          0x0417212d _ZL16backing_callbackP9CGContextPv + 88
49  QuartzCore                          0x0409215d CABackingStoreUpdate_ + 2636
50  QuartzCore                          0x04171fd2 _ZN2CA5Layer8display_Ev + 1370
51  QuartzCore                          0x0415fcf1 -[CALayer _display] + 33
52  QuartzCore                          0x04166281 _ZN2CA5Layer7displayEv + 165
53  QuartzCore                          0x0415fd17 -[CALayer display] + 33
54  QuartzCore                          0x04169c5c _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 256
55  QuartzCore                          0x040effb9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 395
56  QuartzCore                          0x040f1ea6 _ZN2CA11Transaction6commitEv + 374
57  QuartzCore                          0x040f1580 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 80
58  CoreFoundation                      0x011959ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
59  CoreFoundation                      0x0112c670 __CFRunLoopDoObservers + 384
60  CoreFoundation                      0x010f84f6 __CFRunLoopRun + 1174
61  CoreFoundation                      0x010f7db4 CFRunLoopRunSpecific + 212
62  CoreFoundation                      0x010f7ccb CFRunLoopRunInMode + 123
63  GraphicsServices                    0x04789879 GSEventRunModal + 207
64  GraphicsServices                    0x0478993e GSEventRun + 114
65  UIKit                               0x02190a9b UIApplicationMain + 1175
66  ???                                 0x0cda47fd 0x0 + 215631869
67  ???                                 0x0cc78ea0 0x0 + 214404768
68  ???                                 0x0cc78b98 0x0 + 214403992
69  ???                                 0x0cc78cee 0x0 + 214404334
70  MyApp                               0x00009ff2 mono_jit_runtime_invoke + 722
71  MyApp                               0x00169eee mono_runtime_invoke + 126
72  MyApp                               0x0016dfd4 mono_runtime_exec_main + 420
73  MyApp                               0x001733f5 mono_runtime_run_main + 725
74  MyApp                               0x000671f5 mono_jit_exec + 149
75  MyApp                               0x002116c9 main + 2825
76  MyApp                               0x00003045 start + 53

   =================================================================
   Got a SIGSEGV while executing native code. This usually indicates
   a fatal error in the mono runtime or one of the native libraries 
   used by your application.
   =================================================================

回答1:

It's a case of Autocorrection strikes back, aka bug #325 (and quite a few duplicates) and it's not MonoTouch specific.

Something, deep down, the simulated iOS gets corrupted and shows up while it wants to draw it's little red line to show something is misspelled.

This will only happen in the simulator and only when an UITextField has auto-correction enabled. Turning it off like this:

new EntryElement("that contains spaces", string.Empty, string.Empty) {
    AutocorrectionType = UITextAutocorrectionType.No
}

will solve the issue (and you can do it only for your simulator builds with a #define).