MonoTouch Fatal Crash once deployed

0

I've found that I'm getting an error once I've deployed a solution to iPhone 4s which is causing the app to crash without raising any errors within MonoTouch. I'm handling the UIApplication.Main and writing to error log any exceptions, and none are being raised.

I've tracked it down to a line of code which I've deployed to iPad without this issue, the line is within the AppDelegate class:

[DllImport(MonoTouch.Constants.SystemLibrary)]  
    internal static extern int sysctlbyname( [MarshalAs(UnmanagedType.LPStr)] string property, IntPtr output, IntPtr oldLen, IntPtr newp, uint newlen);  

It crashes the app out, but remains in the task list, rather than forcefully closing the whole app.

The Device Log on crashing is:

Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: Native stacktrace:
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     0   RWMAppStore                         0x004917b4 RWMAppStore + 4786100
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     1   RWMAppStore                         0x0047bde0 RWMAppStore + 4697568
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     2   libsystem_c.dylib                   0x3620e539 _sigtramp + 48
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     3   RWMAppStore                         0x004dd98c RWMAppStore + 5097868
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     4   RWMAppStore                         0x004dd98c RWMAppStore + 5097868
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     5   RWMAppStore                         0x00574a84 RWMAppStore + 5716612
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     6   RWMAppStore                         0x004bdb40 RWMAppStore + 4967232
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     7   RWMAppStore                         0x004de134 RWMAppStore + 5099828
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     8   RWMAppStore                         0x005483a0 RWMAppStore + 5534624
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     9   RWMAppStore                         0x00560764 RWMAppStore + 5633892
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     10  RWMAppStore                         0x0057b034 RWMAppStore + 5742644
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     11  libsystem_c.dylib                   0x361c5c1d _pthread_start + 320
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>:     12  libsystem_c.dylib                   0x361c5ad8 thread_start + 8
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: =================================================================
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: Got a SIGSEGV while executing native code. This usually indicates
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: a fatal error in the mono runtime or one of the native libraries 
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: used by your application.
Mar 13 14:35:18 unknown UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5][5456] <Notice>: =================================================================
Mar 13 14:35:19 unknown ReportCrash[5458] <Notice>: Formulating crash report for process RWMAppStore[5456]
Mar 13 14:35:19 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:come.redware-mobile.iphoneappstore[0x91f5]) Job appears to have crashed: Abort trap: 6
Mar 13 14:35:19 unknown SpringBoard[15] <Warning>: Application 'App Store Front' exited abnormally with signal 6: Abort trap: 6

The crash report is:

    Incident Identifier: 49661917-C8E0-4FBB-9E21-1B9443B3443A
CrashReporter Key:   521c0afd53359e09a1e4eaae6ed1eda8500c4ebb
Hardware Model:      iPhone4,1
Process:         RWMAppStore [6537]
Path:            /var/mobile/Applications/A2345805-B9C2-412E-BCEA-0A45D7CC7358/RWMAppStore.app/RWMAppStore
Identifier:      RWMAppStore
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2012-03-14 13:53:06.552 +0000
OS Version:      iPhone OS 5.0.1 (9A405)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000011d
Crashed Thread:  9

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x33627010 0x33626000 + 4112
1   libsystem_kernel.dylib          0x33627206 0x33626000 + 4614
2   CoreFoundation                  0x37d7141c 0x37ce4000 + 578588
3   CoreFoundation                  0x37d7011a 0x37ce4000 + 573722
4   CoreFoundation                  0x37cf34d6 0x37ce4000 + 62678
5   CoreFoundation                  0x37cf339e 0x37ce4000 + 62366
6   GraphicsServices                0x37871fc6 0x3786e000 + 16326
7   UIKit                           0x3518373c 0x35152000 + 202556
8   RWMAppStore                     0x0023adf8 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr (monotouch.dll.6.s:33721)
9   RWMAppStore                     0x00100b04 RWMAppStore_Application_Main_string__ (RWMAppStore.exe.6.s:21)
10  RWMAppStore                     0x003d0d20 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr (mscorlib.dll.6.s:160144)
11  RWMAppStore                     0x0047ddf8 mono_jit_runtime_invoke (mini.c:5786)
12  RWMAppStore                     0x00525224 mono_runtime_invoke (object.c:2757)
13  RWMAppStore                     0x005294d0 mono_runtime_exec_main (object.c:3932)
14  RWMAppStore                     0x0052e144 mono_runtime_run_main (object.c:3562)
15  RWMAppStore                     0x00482180 mono_jit_exec (driver.c:1112)
16  RWMAppStore                     0x0047a3e4 main (main.m:1702)
17  RWMAppStore                     0x00002730 0x1000 + 5936

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x336273b4 0x33626000 + 5044
1   libdispatch.dylib               0x37a5bf74 0x37a58000 + 16244
2   libdispatch.dylib               0x37a5bc92 0x37a58000 + 15506

Thread 2:
0   libsystem_kernel.dylib          0x33637cd4 0x33626000 + 72916
1   libsystem_c.dylib               0x361c030a 0x361b6000 + 41738
2   libsystem_c.dylib               0x361c009c 0x361b6000 + 41116

Thread 3:
0   libsystem_kernel.dylib          0x33637cd4 0x33626000 + 72916
1   libsystem_c.dylib               0x361c030a 0x361b6000 + 41738
2   libsystem_c.dylib               0x361c009c 0x361b6000 + 41116

Thread 4 name:  WebThread
Thread 4:
0   libsystem_kernel.dylib          0x33627010 0x33626000 + 4112
1   libsystem_kernel.dylib          0x33627206 0x33626000 + 4614
2   CoreFoundation                  0x37d7141c 0x37ce4000 + 578588
3   CoreFoundation                  0x37d70154 0x37ce4000 + 573780
4   CoreFoundation                  0x37cf34d6 0x37ce4000 + 62678
5   CoreFoundation                  0x37cf339e 0x37ce4000 + 62366
6   WebCore                         0x325c4128 0x3251c000 + 688424
7   libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
8   libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 5:
0   libsystem_kernel.dylib          0x33637628 0x33626000 + 71208
1   libsystem_c.dylib               0x361c9ff2 0x361b6000 + 81906
2   RWMAppStore                     0x0055f8f8 SleepEx (wthreads.c:1027)
3   RWMAppStore                     0x0053f494 monitor_thread (threadpool.c:781)
4   RWMAppStore                     0x00548398 start_wrapper (threads.c:784)
5   RWMAppStore                     0x0056075c thread_start_routine (wthreads.c:287)
6   RWMAppStore                     0x0057b02c GC_start_routine (pthread_support.c:1468)
7   libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
8   libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 6:
0   libsystem_kernel.dylib          0x33627078 0x33626000 + 4216
1   RWMAppStore                     0x0056708c mono_sem_timedwait (mono-semaphore.c:76)
2   RWMAppStore                     0x005421a8 async_invoke_thread (threadpool.c:1497)
3   RWMAppStore                     0x00548398 start_wrapper (threads.c:784)
4   RWMAppStore                     0x0056075c thread_start_routine (wthreads.c:287)
5   RWMAppStore                     0x0057b02c GC_start_routine (pthread_support.c:1468)
6   libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
7   libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 7:
0   libsystem_kernel.dylib          0x336273b4 0x33626000 + 5044
1   RWMAppStore                     0x005404dc tp_kqueue_wait (tpool-kqueue.c:98)
2   RWMAppStore                     0x00548398 start_wrapper (threads.c:784)
3   RWMAppStore                     0x0056075c thread_start_routine (wthreads.c:287)
4   RWMAppStore                     0x0057b02c GC_start_routine (pthread_support.c:1468)
5   libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
6   libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 8:
0   libsystem_kernel.dylib          0x33627078 0x33626000 + 4216
1   RWMAppStore                     0x0056708c mono_sem_timedwait (mono-semaphore.c:76)
2   RWMAppStore                     0x005421a8 async_invoke_thread (threadpool.c:1497)
3   RWMAppStore                     0x00548398 start_wrapper (threads.c:784)
4   RWMAppStore                     0x0056075c thread_start_routine (wthreads.c:287)
5   RWMAppStore                     0x0057b02c GC_start_routine (pthread_support.c:1468)
6   libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
7   libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 9 Crashed:
0   libsystem_kernel.dylib          0x3363732c 0x33626000 + 70444
1   libsystem_c.dylib               0x36203f54 0x361b6000 + 319316
2   libsystem_c.dylib               0x361fcfe4 0x361b6000 + 290788
3   RWMAppStore                     0x00491980 mono_handle_native_sigsegv (mini-exceptions.c:2255)
4   RWMAppStore                     0x0047bdd8 mono_sigsegv_signal_handler (mini.c:5923)
5   libsystem_c.dylib               0x3620e532 0x361b6000 + 361778
6   RWMAppStore                     0x004dd984 mono_gc_run_finalize (gc.c:113)
7   RWMAppStore                     0x004dd984 mono_gc_run_finalize (gc.c:113)
8   RWMAppStore                     0x00574a7c GC_invoke_finalizers (finalize.c:787)
9   RWMAppStore                     0x004bdb38 mono_gc_invoke_finalizers (boehm-gc.c:549)
10  RWMAppStore                     0x004de12c finalizer_thread (gc.c:1055)
11  RWMAppStore                     0x00548398 start_wrapper (threads.c:784)
12  RWMAppStore                     0x0056075c thread_start_routine (wthreads.c:287)
13  RWMAppStore                     0x0057b02c GC_start_routine (pthread_support.c:1468)
14  libsystem_c.dylib               0x361c5c16 0x361b6000 + 64534
15  libsystem_c.dylib               0x361c5ad0 0x361b6000 + 64208

Thread 9 crashed with ARM Thread State:
    r0: 0x00000000    r1: 0x00000000      r2: 0x00000001      r3: 0x00000000
    r4: 0x00000006    r5: 0x073f6000      r6: 0x00000000      r7: 0x073f5464
    r8: 0x3f1eb060    r9: 0x00000000     r10: 0x001068ca     r11: 0x01b40234
    ip: 0x00000148    sp: 0x073f5458      lr: 0x36203f5b      pc: 0x3363732c
  cpsr: 0x00000010
xamarin.ios
asked on Stack Overflow Mar 13, 2012 by davoc bradley • edited Mar 14, 2012 by davoc bradley

1 Answer

1

It looks like the heap has become corrupted somehow. I can't find anything immediately wrong in the code you're using, but maybe you can try changing this line:

var pStr = Marshal.AllocHGlobal(length);

to

var pStr = Marshal.AllocHGlobal(length * 2);

to see if that works around the issue.

I might be able to get my hands on an iPhone soon where I can test it.

Update

I've tried this on an iPhone4, and it does not crash. This means that it's probably several different things in your app that plays together to create this crash, and the best way to fix/find it would be to file a bug at http://bugzilla.xamarin.com and attaching your project (you can mark the bug private so only Xamarin employees can see it if your project is closed source).

answered on Stack Overflow Mar 14, 2012 by Rolf Bjarne Kvinge • edited Mar 14, 2012 by Rolf Bjarne Kvinge

User contributions licensed under CC BY-SA 3.0