samedi 25 juin 2016

Xamarin.iOS bind Objective C block to the C# code

I'm working on a Xamarin.iOS binding for the following Objective C code @interface Logger : NSObject + (void)setLogBlock:(void (^)(NSString* message, void* argument))logBlock; @end So far I have following code: // @interface Logger : NSObject [BaseType(typeof(NSObject))] public partial interface Logger { // +(void)setLogBlock:(void (^)(NSString *, void *))logBlock; [Static] [Export("setLogBlock:")] void SetLogBlock(LogDelegate logBlock); } // This declares the callback signature for the block: public delegate void LogDelegate(NSString message, IntPtr arg); This compiles fine but the app crashes when I start using it with following crash on iOS Simulator: 2016-06-24 16:47:01.047 BindingTest[26019:1633387] critical: Native stacktrace: 2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 0 libmonosgen-2.0.dylib 0x09cf2f4d mono_handle_native_sigsegv + 317 2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 1 libmonosgen-2.0.dylib 0x09c419f6 mono_sigsegv_signal_handler + 214 2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 2 libsystem_platform.dylib 0x0c3ef79b _sigtramp + 43 2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 3 ??? 0xffffffff 0x0 + 4294967295 2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 4 libdispatch.dylib 0x0c099456 dispatch_async + 342 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 5 BindingTest 0x00069ba3 otk_objc_log + 276 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 6 BindingTest 0x00537207 otk_console_append + 295 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 7 BindingTest 0x005385bb otk_ev_timer_callback + 155 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 8 BindingTest 0x0050ef4f uv__run_timers + 159 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 9 BindingTest 0x004fcba8 uv_run + 120 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 10 BindingTest 0x00538f74 otk_ev_thread_main + 148 2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 11 BindingTest 0x00065f78 otkit_session_start_thread + 21 2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 12 libsystem_pthread.dylib 0x0c3dc780 _pthread_body + 138 2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 13 libsystem_pthread.dylib 0x0c3dc6f6 _pthread_body + 0 2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 14 libsystem_pthread.dylib 0x0c3d9f7a thread_start + 34 2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: ================================================================= 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. ================================================================= iOS device crashes with following stack trace: Jun 24 19:11:26 am-6s Test[4795] <Warning>: ------------------------------------------------ Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: Stacktrace: Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at <unknown> <0xffffffff> Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at (wrapper managed-to-native) System.Runtime.InteropServices.GCHandle.CheckCurrentDomain (int) <0x00007> Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at System.Runtime.InteropServices.GCHandle.op_Explicit (intptr) [0x0001b] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:124 Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at System.Runtime.InteropServices.GCHandle.FromIntPtr (intptr) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:166 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at ObjCRuntime.BlockLiteral.get_Target () [0x00015] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/src/ObjCRuntime/Blocks.cs:126 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke (intptr,intptr,intptr) [0x00009] in ....iOS/obj/Debug/ios/ObjCRuntime/Trampolines.g.cs:60 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at (wrapper native-to-managed) ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke (intptr,intptr,intptr) <0x000a7> Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: Native stacktrace: Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 0 libmonosgen-2.0.dylib 0x00000001008fe438 mono_handle_native_sigsegv + 260 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 1 libmonosgen-2.0.dylib 0x0000000100909074 mono_sigsegv_signal_handler + 336 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 2 libsystem_platform.dylib 0x00000001830d994c _sigtramp + 68 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 3 libmonosgen-2.0.dylib 0x0000000100991334 mono_gchandle_is_in_domain + 20 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 4 libmonosgen-2.0.dylib 0x000000010093e174 mono_gc_GCHandle_CheckCurrentDomain + 32 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 5 libmscorlib.dll.dylib 0x0000000100ef1ec0 wrapper_managed_to_native_System_Runtime_InteropServices_GCHandle_CheckCurrentDomain_int + 96 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 6 libmscorlib.dll.dylib 0x0000000100ef1de8 System_Runtime_InteropServices_GCHandle_op_Explicit_intptr + 56 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 7 libmscorlib.dll.dylib 0x0000000100ef22fc System_Runtime_InteropServices_GCHandle_FromIntPtr_intptr + 28 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 8 libXamarin.iOS.dll.dylib 0x0000000100c92b8c ObjCRuntime_BlockLiteral_get_Target + 76 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 9 libOpenTok.iOS.dll.dylib 0x00000001020a05bc ObjCRuntime_Trampolines_SDOpenTokLogBlockDelegate_Invoke_intptr_intptr_intptr + 236 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 10 libOpenTok.iOS.dll.dylib 0x00000001020b07f8 wrapper_native_to_managed_ObjCRuntime_Trampolines_SDOpenTokLogBlockDelegate_Invoke_intptr_intptr_intptr + 168 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 11 libOpenTok.iOS.dll.dylib 0x0000000101b38428 __otk_objc_log_block_invoke6 + 48 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 12 libdispatch.dylib 0x0000000182ec54bc <redacted> + 24 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 13 libdispatch.dylib 0x0000000182ec547c <redacted> + 16 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 14 libdispatch.dylib 0x0000000182ed14c0 <redacted> + 864 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 15 libdispatch.dylib 0x0000000182ec8f80 <redacted> + 464 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 16 libdispatch.dylib 0x0000000182ed3390 <redacted> + 728 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 17 libdispatch.dylib 0x0000000182ed30b0 <redacted> + 112 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 18 libsystem_pthread.dylib 0x00000001830dd470 _pthread_wqthread + 1092 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 19 libsystem_pthread.dylib 0x00000001830dd020 start_wqthread + 4 Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: ================================================================= 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. ================================================================= Please advise.

Aucun commentaire:

Enregistrer un commentaire