Bound Xamarin.iOS library subclass crashes on simulator

0

I'm currently having an issue with the iOS simulator.

I'm currently developing a Xamarin project with a bound Objective-C library (ECSlidingViewController). I built the library for the armv7, armv7s, simulator and arm64 architectures, combined them into a fat binary and bound it using a Xamarin binding project.

Now the binding works fine for the most part, except for one small tidbit. Whenever I subclass the ECSlidingViewController class contained in the bound library and try to use the subclass in my application, the application terminates when I try to call AnchorTopViewToRightAnimated(bool animated). All other properties and methods work fine.

The method is bound like this:

[BaseType (typeof (UIViewController))]
interface ECSlidingViewController {
            //...

            [Export ("anchorTopViewToRightAnimated:")]
        void AnchorTopViewToRightAnimated (bool animated);
}

This only happens on the simulator and only when accessing the method on a subclass (even if that subclass is casted to it's parent type). It works fine when called on a non-subclassed ECSlidingViewController instance or when run on a device. After the application terminates the debug output doesn't contain any related errors. The only information I could find was this crash log in the OS X console:

Process:         TTWebApp [851]
Path:            /Users/USER/Library/Application Support/iPhone Simulator/*/TTWebApp.app/TTWebApp
Identifier:      TTWebApp
Version:         0
Code Type:       X86 (Native)
Parent Process:  launchd_sim [819]
User ID:         501

Date/Time:       2014-02-06 09:35:01.372 +0100
OS Version:      Mac OS X 10.8.5 (12F37)
Report Version:  10

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000

Application Specific Information:
iPhone Simulator 463.9.4.2, iPhone OS 7.0.3 (iPad/11B508)


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   CoreFoundation                  0x04f3fb71 CFRetain + 113
1   ???                             0x123b5e18 0 + 305880600
2   ???                             0x123b5b28 0 + 305879848
3   ???                             0x123b5d76 0 + 305880438
4   TTWebApp                        0x00167484 mono_jit_runtime_invoke + 820 (mini.c:6622)
5   TTWebApp                        0x0020207f mono_runtime_invoke + 127 (object.c:2827)
6   TTWebApp                        0x002a554a get_delegate_for_block_parameter + 138 (monotouch-glue.m:292)
7   TTWebApp                        0x002ac8f7 monotouch_trampoline + 1847 (.monotouch-trampoline-setup-callstack.inc:70)
8   TTWebApp                        0x0007d3f7 -[ECSlidingViewController anchorTopViewToRightAnimated:] + 49 (ECSlidingViewController.m:412)
9   ???                             0x120f6688 0 + 302999176
10  ???                             0x120f7fc4 0 + 303005636
11  ???                             0x120f7daf 0 + 303005103
12  ???                             0x120f7d38 0 + 303004984
13  ???                             0x0fee1cef 0 + 267263215
14  TTWebApp                        0x00167484 mono_jit_runtime_invoke + 820 (mini.c:6622)
15  TTWebApp                        0x0020207f mono_runtime_invoke + 127 (object.c:2827)
16  TTWebApp                        0x002ad21a monotouch_trampoline + 4186 (.monotouch-trampoline-invoke.inc:1)
17  libobjc.A.dylib                 0x04d8f874 -[NSObject performSelector:withObject:withObject:] + 77
18  UIKit                           0x032eb0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
19  UIKit                           0x035bfc9b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
20  libobjc.A.dylib                 0x04d8f874 -[NSObject performSelector:withObject:withObject:] + 77
21  UIKit                           0x032eb0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
22  UIKit                           0x032eb04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
23  UIKit                           0x033e30c1 -[UIControl sendAction:to:forEvent:] + 66
24  UIKit                           0x033e3484 -[UIControl _sendActionsForEvents:withEvent:] + 577
25  UIKit                           0x033e2733 -[UIControl touchesEnded:withEvent:] + 641
26  UIKit                           0x0332851d -[UIWindow _sendTouchesForEvent:] + 852
27  UIKit                           0x03329184 -[UIWindow sendEvent:] + 1232
28  UIKit                           0x032fce86 -[UIApplication sendEvent:] + 242
29  UIKit                           0x032e718f _UIApplicationHandleEventQueue + 11421
30  CoreFoundation                  0x04f4d83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
31  CoreFoundation                  0x04f4d1cb __CFRunLoopDoSources0 + 235
32  CoreFoundation                  0x04f6a29e __CFRunLoopRun + 910
33  CoreFoundation                  0x04f69ac3 CFRunLoopRunSpecific + 467
34  CoreFoundation                  0x04f698db CFRunLoopRunInMode + 123
35  GraphicsServices                0x0654f9e2 GSEventRunModal + 192
36  GraphicsServices                0x0654f809 GSEventRun + 104
37  UIKit                           0x032e9d3b UIApplicationMain + 1225
38  ???                             0x10eefb00 0 + 284097280
39  ???                             0x10eedc1c 0 + 284089372
40  ???                             0x10eed7f8 0 + 284088312
41  ???                             0x10eed937 0 + 284088631
42  TTWebApp                        0x00167484 mono_jit_runtime_invoke + 820 (mini.c:6622)
43  TTWebApp                        0x0020207f mono_runtime_invoke + 127 (object.c:2827)
44  TTWebApp                        0x002078c7 mono_runtime_exec_main + 391 (object.c:4050)
45  TTWebApp                        0x00207694 mono_runtime_run_main + 628 (object.c:3678)
46  TTWebApp                        0x000d135d mono_jit_exec + 93 (driver.g.c:1009)
47  TTWebApp                        0x0029f7e4 main + 2788 (main.m:489)
48  libdyld.dylib                   0x05a7c725 start + 1

Thread 1:: Dispatch queue: com.apple.libdispatch-manager
0   libsystem_kernel.dylib          0x05c4c9ca kevent64 + 10
1   libdispatch.dylib               0x057c6f3e _dispatch_mgr_invoke + 238
2   libdispatch.dylib               0x057c6c7a _dispatch_mgr_thread + 60

Thread 2:
0   libsystem_kernel.dylib          0x05c4c0ee __workq_kernreturn + 10
1   libsystem_c.dylib               0x05b090ac _pthread_workq_return + 45
2   libsystem_c.dylib               0x05b08e79 _pthread_wqthread + 448
3   libsystem_c.dylib               0x05af0daa start_wqthread + 30

Thread 3:
0   libsystem_kernel.dylib          0x05c4bb3e __recvfrom + 10
1   libsystem_sim_c.dylib           0x0589ca9d recv + 54
2   TTWebApp                        0x002a19dd recv_uninterrupted + 77 (debug.m:321)
3   TTWebApp                        0x002a1c0b monotouch_process_connection + 187 (debug.m:738)
4   TTWebApp                        0x002a17e7 monotouch_connect_wifi + 2983 (debug.m:515)
5   TTWebApp                        0x002a08ac monotouch_configure_debugging + 2124 (debug.m:269)
6   TTWebApp                        0x0029e2ea -[CocoaThreadInitializer entryPoint:] + 122 (shared.m:127)
7   Foundation                      0x01aaf597 -[NSThread main] + 76
8   Foundation                      0x01aaf4f6 __NSThread__main__ + 1275
9   libsystem_c.dylib               0x05b065b7 _pthread_start + 344
10  libsystem_c.dylib               0x05af0dce thread_start + 34

Thread 4:
0   libsystem_kernel.dylib          0x05c4980a semaphore_wait_trap + 10
1   TTWebApp                        0x0027967a mono_sem_wait + 26 (mono-semaphore.c:121)
2   TTWebApp                        0x001aa2d7 finalizer_thread + 103 (gc.c:1078)
3   TTWebApp                        0x00239ab8 start_wrapper + 376 (threads.c:609)
4   TTWebApp                        0x0026dcd7 thread_start_routine + 151 (wthreads.c:294)
5   TTWebApp                        0x00279d31 inner_start_thread + 65 (mono-threads-posix.c:49)
6   TTWebApp                        0x0029b51d GC_start_routine + 93 (pthread_support.c:1502)
7   libsystem_c.dylib               0x05b065b7 _pthread_start + 344
8   libsystem_c.dylib               0x05af0dce thread_start + 34

Thread 5:
0   libsystem_kernel.dylib          0x05c4bb3e __recvfrom + 10
1   libsystem_sim_c.dylib           0x0589ca9d recv + 54
2   TTWebApp                        0x002a19dd recv_uninterrupted + 77 (debug.m:321)
3   TTWebApp                        0x002a1ad4 sdb_recv + 52 (debug.m:337)
4   TTWebApp                        0x000bc0fb debugger_thread + 22427 (debugger-agent.c:1475)
5   TTWebApp                        0x0026dcd7 thread_start_routine + 151 (wthreads.c:294)
6   TTWebApp                        0x00279d31 inner_start_thread + 65 (mono-threads-posix.c:49)
7   TTWebApp                        0x0029b51d GC_start_routine + 93 (pthread_support.c:1502)
8   libsystem_c.dylib               0x05b065b7 _pthread_start + 344
9   libsystem_c.dylib               0x05af0dce thread_start + 34

Thread 6:
0   libsystem_kernel.dylib          0x05c4bc72 __semwait_signal + 10
1   libsystem_sim_c.dylib           0x0589c98b nanosleep + 219
2   libsystem_sim_c.dylib           0x0589c836 usleep + 60
3   TTWebApp                        0x002a62bd monotouch_pump_gc + 61 (monotouch-glue.m:595)
4   libsystem_c.dylib               0x05b065b7 _pthread_start + 344
5   libsystem_c.dylib               0x05af0dce thread_start + 34

Thread 7:
0   libsystem_kernel.dylib          0x05c4c0ee __workq_kernreturn + 10
1   libsystem_c.dylib               0x05b090ac _pthread_workq_return + 45
2   libsystem_c.dylib               0x05b08e79 _pthread_wqthread + 448
3   libsystem_c.dylib               0x05af0daa start_wqthread + 30

Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x00000000  ebx: 0x00000000  ecx: 0x04f3fb00  edx: 0x00000000
  edi: 0x04f3fb0e  esi: 0x00000000  ebp: 0xbff8ccc8  esp: 0xbff8ccb0
   ss: 0x00000023  efl: 0x00000246  eip: 0x04f3fb71   cs: 0x0000001b
   ds: 0x00000023   es: 0x00000023   fs: 0x00000000   gs: 0x0000000f
  cr2: 0x10165e98
Logical CPU: 0
c#
ios
xamarin.ios
xamarin
asked on Stack Overflow Feb 6, 2014 by Leon Lucardie

1 Answer

3

My guess is that your binding include a method that takes a C# delegate, and that delegate can be null. Unfortunately Xamarin.iOS does not support binding a delegate that can be null yet.

There are a few workarounds you can try:

  • Use IntPtr instead of a delegate type in the method signature. This will make the method itself quite useless, since you won't be able to call it with your own delegate.
  • Remove the method in question completely, with the same consequences as above.
  • Pass --registrar:dynamic as an additional mtouch argument in the project's iOS Build options. This will work around the problem by not actually exposing your method to Objective-C until a subclass overrides it (in which case you'd end up with the same crash as you have now). The downside is that you'll have to document that this flag is mandatory for all the consumers of your library.
answered on Stack Overflow Feb 6, 2014 by Rolf Bjarne Kvinge • edited Feb 6, 2014 by Rolf Bjarne Kvinge

User contributions licensed under CC BY-SA 3.0