简体   繁体   English

绑定的Xamarin.iOS库子类在模拟器上崩溃

[英]Bound Xamarin.iOS library subclass crashes on simulator

I'm currently having an issue with the iOS simulator. 我目前在iOS模拟器上遇到问题。

I'm currently developing a Xamarin project with a bound Objective-C library (ECSlidingViewController). 我目前正在开发具有绑定的Objective-C库(ECSlidingViewController)的Xamarin项目。 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. 我为armv7,armv7s,模拟器和arm64体系结构构建了库,将它们组合成一个胖二进制文件,并使用Xamarin绑定项目对其进行了绑定。

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) . 每当我对绑定库中包含的ECSlidingViewController类进行子类化并尝试在应用程序中使用该子类时,当我尝试调用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. 在非子类ECSlidingViewController实例上ECSlidingViewController或在设备上运行时,它可以正常工作。 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: 我能找到的唯一信息是OS X控制台中的此崩溃日志:

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

My guess is that your binding include a method that takes a C# delegate, and that delegate can be null. 我的猜测是您的绑定包含一个采用C#委托的方法,并且该委托可以为null。 Unfortunately Xamarin.iOS does not support binding a delegate that can be null yet. 不幸的是Xamarin.iOS不支持绑定可以为null的委托。

There are a few workarounds you can try: 您可以尝试以下几种解决方法:

  • Use IntPtr instead of a delegate type in the method signature. 在方法签名中使用IntPtr代替委托类型。 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. 在项目的iOS Build选项中,将--registrar:dynamic作为附加的mtouch参数传递。 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). 通过在子类重写该方法之前不将您的方法实际暴露给Objective-C,可以解决该问题(在这种情况下,您将遇到与现在相同的崩溃)。 The downside is that you'll have to document that this flag is mandatory for all the consumers of your library. 缺点是您必须证明该标志对于库的所有使用者都是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM