Thanks Jeff for the quick response! You saved my day, the binding now works
like a charm.

All the best,
Patrik



On 10 April 2013 20:11, Jeff Stedfast <[email protected]> wrote:

> Hi Patrik,
>
> The problem appears to be that SendTag...()'s thread uses the NSString
> that gets passed to it as an argument after it has already been free'd.
>
>
>    1. [Export ("sendTagWithCategory:")]
>    2. int SendTagWithCategory (string category);
>
>
> This will generate code similar to this:
>
> int SendTagWithCategory (string category)
> {
>     NSString str = new NSString (category);
>     int retval = dispatch_to_objective_c (str);
>     str.Dispose ();
>     return retval;
> }
>
> As you can see in the above pseudo-binding, the NSString gets immediately
> disposed after making the call to Objective-C because it doesn't know that
> it shouldn't do that (and I think Apple's coding guidelines state that
> these sorts of APIs should clone the input parameters if they intend to use
> it asynchronously).
>
> To work around this issue, you'll need to change your binding to:
>
>
>    1. [Export ("sendTagWithCategory:")]
>    2. int SendTagWithCategory (NSString category);
>
>
> Once you do that, you'll need to keep your copy of the category string
> cached somewhere (such as a member variable on whatever class is calling
> TSMobileTagging.SendTagWithCategory()) until you know that the thread had
> completed (unfortunately there doesn't seem to be a way to do that?). You
> might also be able to define some global NSString category string values
> that you use instead of passing around .NET strings.
>
> Hope that helps,
>
> Jeff
>
> On Wed, Apr 10, 2013 at 1:16 PM, Patrik Ahlenius <[email protected]>wrote:
>
>> Hi,
>>
>> I'm trying to bind an Objective-C library but have run into a problem.
>> One of the methods in the binding only works in roughly 1 out of 10 calls,
>> and for the most time crashes the app with a SIGSEGV. The functions that
>> crashes does according to the library docs spawn of a new thread which
>> opens a network connection. Can threading be a part of the problem?
>>
>> The binding itself is is light, and only binds three methods. Attached at
>> the bottom are pastebins to the crashlog (as well as my binding, and the
>> Obj-C. headers for the functions bound)
>>
>> Realize that it probably is most likely diffuclt to give any pointers on
>> what could be wrong, but figured i give it a shot anyway in case anyone has
>> experienced something similair.
>>
>> Best regards,
>> Patrik
>>
>> Success/Crashlog: http://pastebin.com/SGVFs8XQ
>>
>> My binding: http://pastebin.com/ArkHvJHE
>>
>> Obj-C headers (without unbound methods omitted) :
>> http://pastebin.com/EVcms9f3
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [email protected]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to