下午,
我在本机代码中使用相同的Xamarin.iOS绑定大约3年完美无瑕地工作但最近我注意到了从一开始就可能存在的崩溃行为。我处理大型(也是小型)数组的绑定,如图像等。
问题:看起来GC正在收集一些结构,而对本机的非托管调用正在运行。我正在盯着'涉及的数据和方法绑定调用不安全的固定语句。
fixed (double* px = _px)
{
fixed (double* py = _py)
{
fixed (double* param = parameters)
{
fixed (int* distMap = _distMap)
{
IntPtr dataPxPtr = new IntPtr((void*)px);
IntPtr dataPyPtr = new IntPtr((void*)py);
IntPtr parametersPtr = new IntPtr((void*)param);
IntPtr distMapPtr = new IntPtr((void*)distMap);
_bindings.Initiate(dataPxPtr, dataPyPtr, parametersPtr, distMapPtr, 1E-4, Size.Width);
_bindings.Iterate();
}
}
}
}
理论上,嵌套的固定语句应该在绑定方法运行时固定内存地址。但事实似乎并非如此......
Xamarin Side Stacktrace
Warning (239) / iOSApp: critical: at <unknown> <0xffffffff>
Warning (239) / iOSApp: critical: at (wrapper managed-to-native) ...Messaging.void_objc_msgSend (intptr,intptr) <0x00007>
Warning (239) / iOSApp: critical: at ...Bindings.Iterate () <0x00047>
XCode Stacktrace
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000001088fc018
Triggered by Thread: 4
Thread 4 name: tid_681f
Thread 4 Crashed:
0 libsystem_kernel.dylib 0x0000000182cac11c __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000182d78ef8 pthread_kill + 112
2 libsystem_c.dylib 0x0000000182c1ddc8 abort + 140
3 iOSApp 0x0000000100ed26cc mono_handle_native_sigsegv (mini-exceptions.c:2462)
4 iOSApp 0x0000000100eddccc mono_sigsegv_signal_handler (mini-runtime.c:2906)
5 libsystem_platform.dylib 0x0000000182d7194c _sigtramp + 68
6 iOSApp 0x00000001000ed77c lmdif_ (lmdif_.c:468)
7 iOSApp 0x00000001000f1e44 lmdif1_ (lmdif1_.c:153)
8 iOSApp 0x00000001000ec3c8 -[Bindings iterate] (Bindings.m:403)
9 iOSApp 0x0000000101bf1698 wrapper_managed_to_native_Bindings_Messaging_void_objc_msgSend_intptr_intptr (/<unknown>:1)
10 iOSApp 0x0000000101bf0428 Bindings_Iterate (/<unknown>:1)
我已经尝试过,但没有成功:
任何帮助都会受到赞赏,因为我疯了。
谢谢,
安东尼奥