[MonoTouch] EXC_BAD_ACCESS with NSString sizeWithFont:constrainedToSize:lineBreakMode:

Ed Anuff ed at anuff.com
Fri Oct 16 12:00:51 EDT 2009


D'oh!

FWIW, I was also able to fix the problem by using objc_msgSend_stret.
The page at http://monotouch.net/Documentation/Objective-C_Selectors
that describes using selectors unfortunately uses sizeWithFont as the
example for regular selector usage without explicitly mentioning that
it's also an example of the type of selector which must use the _stret
invocation method, instead using selConvertPointFromWindow as the
example of when you need to use objc_msgSend_stret.

Ed

On Fri, Oct 16, 2009 at 5:40 AM, Geoff Norton <gnorton at novell.com> wrote:
> Ed,
>
>  Try UIView.StringSize (msg, font, max_size, mode);
>
> -g
>
> On 16-Oct-09, at 2:55 AM, Ed Anuff wrote:
>
>> I'm trying to use the sizeWithFont method in NSString using the
>> following code.  It works fine on the simulator, but crashes on the
>> device.  Any thought on how to fix this?
>>
>>
>> public static SizeF StringSizeWithFontConstrainedToSize(string msg,
>> UIFont font, SizeF max_size, UILineBreakMode mode)
>> {
>>        NSString target = new NSString(msg);
>>        Selector selector = new Selector
>> ("sizeWithFont:constrainedToSize:lineBreakMode:");
>>        SizeF size = cgsize_objc_msgSend_IntPtr_cgsize_int(
>>                target.Handle,
>>                selector.Handle,
>>                font == null ? IntPtr.Zero : font.Handle,
>>                max_size,
>>                mode);
>>        return size;
>> }
>> _______________________________________________
>> MonoTouch mailing list
>> MonoTouch at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/monotouch
>
>


More information about the MonoTouch mailing list