Occasional SIGSEGV in NSArray binding

谁说胖子不能爱 提交于 2019-12-25 02:58:17

问题


I have the following property that I am binding:

@property (nonatomic, readwrite, retain) NSArray* activeTasks;

That I bind with the following code:

[Export("activeTasks", ArgumentSemantic.Retain)]
NSDictionary[] ActiveTasks { get; } 

I use this property very often. Nevertheless, once every thousand of accesses, I get a SIGSEGV on get_activeTasks (the binding of the selector). I wonder what I am doing wrong and why this only happens very rarely instead of systematically.

  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
  at MonoTouch.Foundation.NSObject.InitializeObject (bool) [0x00062] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:136
  at MonoTouch.Foundation.NSObject..ctor (intptr,bool) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:62
  at MonoTouch.Foundation.NSObject..ctor (intptr) <IL 0x00003, 0x0002b>
  at MonoTouch.Foundation.NSDictionary..ctor (intptr) <IL 0x00002, 0x00027>
  at MonoTouch.Foundation.NSMutableDictionary..ctor (intptr) <IL 0x00002, 0x00027>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___intptr (object,intptr,intptr,intptr) <IL 0x00054, 0xffffffff>
  at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) <IL 0x00030, 0xffffffff>
  at System.Reflection.MonoCMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) [0x00109] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:536
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:551
  at System.Activator.CreateInstance (System.Type,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[]) [0x00174] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:299
  at System.Activator.CreateInstance (System.Type,object[],object[]) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:234
  at System.Activator.CreateInstance (System.Type,object[]) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:229
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (intptr,intptr) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:210
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (intptr) [0x0001f] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:259
  at MonoTouch.Foundation.NSArray.ArrayFromHandle<T> (intptr) [0x0003a] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSArray.cs:172
  at TouchDBBinding.CouchServer.get_ActiveTasks () <IL 0x0001b, 0x00073>

EDIT:

Here is an update stack trace using the new Framework, I don't know if it could help out more:

Stacktrace:

 at (wrapper managed-to-native) MonoTouch.Foundation.NSObject.monotouch_create_managed_ref (intptr,intptr,bool) <IL 0x0002d, 0xffffffff>
  at MonoTouch.Foundation.NSObject.CreateManagedRef (bool) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:93
  at MonoTouch.Foundation.NSObject.InitializeObject (bool) [0x000cc] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:88
  at MonoTouch.Foundation.NSObject..ctor (intptr,bool) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSObject2.cs:85
  at MonoTouch.Foundation.NSObject..ctor (intptr) <IL 0x00003, 0x0002b>
  at MonoTouch.Foundation.NSDictionary..ctor (intptr) <IL 0x00002, 0x00027>
  at MonoTouch.Foundation.NSMutableDictionary..ctor (intptr) <IL 0x00002, 0x00027>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___intptr (object,intptr,intptr,intptr) <IL 0x00054, 0xffffffff>
  at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) <IL 0x00030, 0xffffffff>
  at System.Reflection.MonoCMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) [0x00109] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:530
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:545
  at System.Reflection.ConstructorInfo.Invoke (object[]) [0x0000e] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (intptr,intptr) [0x00051] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:269
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (intptr) [0x0001f] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:328
  at MonoTouch.Foundation.NSArray.ArrayFromHandle<T> (intptr) [0x00044] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSArray.cs:188
  at TouchDBBinding.CouchServer.get_ActiveTasks () <IL 0x0001b, 0x00073>

Is it possible that there is something in the inner workings of MonoTouch that can be a problem when an NSArray* with retain is bound to an NSDictionary[] and that this said property is null? Or is it possible that it is because it has null content?

Thanks, Paul


回答1:


The stack trace indicates that the crash happens when MonoTouch tries to retain one of the elements of the NSArray.

One possible reason is that the particular element has already been freed (or is otherwise corrupted). In particular it is not because the element is null (this case is handled differently).



来源:https://stackoverflow.com/questions/15957609/occasional-sigsegv-in-nsarray-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!