Bug 3998 - Crash in native code when calling NSString.BoundingRectWithSize
Summary: Crash in native code when calling NSString.BoundingRectWithSize
Status: RESOLVED FIXED
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-03-20 18:55 UTC by steven.orth
Modified: 2012-06-21 06:38 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Project to reproduce crash in native code when calling NSString.BoundingRectWithSizeI() (27.80 KB, application/zip)
2012-03-20 18:55 UTC, steven.orth
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description steven.orth 2012-03-20 18:55:59 UTC
Created attachment 1548 [details]
Project to reproduce crash in native code when calling NSString.BoundingRectWithSizeI()

You get a sigsegv when calling this method. I've attached a sample project to illustrate the problem.

Here's a dump.


Stacktrace:

  at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.SizeF_objc_msgSend_SizeF_UInt32_IntPtr (intptr,intptr,System.Drawing.SizeF,uint,intptr) <0xffffffff>
  at MonoMac.Foundation.NSString.BoundingRectWithSize (System.Drawing.SizeF,MonoMac.Foundation.NSStringDrawingOptions,MonoMac.Foundation.NSDictionary) <0x0005f>
  at NSStringBoundsWithSizeCrash.TestView.DrawRect (System.Drawing.RectangleF) <0x000cb>
  at (wrapper dynamic-method) object.[NSStringBoundsWithSizeCrash.TestView.Void DrawRect(RectangleF)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,System.Drawing.RectangleF) <0x0004e>
  at (wrapper native-to-managed) object.[NSStringBoundsWithSizeCrash.TestView.Void DrawRect(RectangleF)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,System.Drawing.RectangleF) <0xffffffff>
  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0xffffffff>
  at MonoMac.AppKit.NSApplication.Main (string[]) <0x00017>
  at NSStringBoundsWithSizeCrash.MainClass.Main (string[]) <0x00017>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	0   NSStringBoundsWithSizeCrash         0x00094efc mono_handle_native_sigsegv + 284
	1   NSStringBoundsWithSizeCrash         0x00004fe8 mono_sigsegv_signal_handler + 248
	2   libsystem_c.dylib                   0x944bc59b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   ???                                 0x034cac0c 0x0 + 55356428
	5   ???                                 0x034cab60 0x0 + 55356256
	6   ???                                 0x034c852c 0x0 + 55346476
	7   ???                                 0x01f506e7 0x0 + 32835303
	8   ???                                 0x034c0dd0 0x0 + 55315920
	9   AppKit                              0x91751295 -[NSView _drawRect:clip:] + 3717
	10  AppKit                              0x91780c32 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1958
	11  AppKit                              0x91780fd3 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2887
	12  AppKit                              0x9174ebf2 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 708
	13  AppKit                              0x9174e1f3 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 259
	14  AppKit                              0x9174987c -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 4817
	15  AppKit                              0x9174279f -[NSView displayIfNeeded] + 1365
	16  AppKit                              0x9173f56d -[NSWindow displayIfNeeded] + 316
	17  AppKit                              0x91742070 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 804
	18  CoreFoundation                      0x946a8f8d _runLoopObserverWithBlockContext + 29
	19  CoreFoundation                      0x9467547e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
	20  CoreFoundation                      0x946753bd __CFRunLoopDoObservers + 413
	21  CoreFoundation                      0x94647c24 __CFRunLoopRun + 1044
	22  CoreFoundation                      0x9464747c CFRunLoopRunSpecific + 332
	23  CoreFoundation                      0x94647328 CFRunLoopRunInMode + 120
	24  HIToolbox                           0x97e7f17f RunCurrentEventLoopInMode + 318
	25  HIToolbox                           0x97e86412 ReceiveNextEventCommon + 168
	26  HIToolbox                           0x97e86356 BlockUntilNextEventMatchingListInMode + 88
	27  AppKit                              0x91701a9c _DPSNextEvent + 678
	28  AppKit                              0x91701306 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
	29  AppKit                              0x916fd675 -[NSApplication run] + 911
	30  AppKit                              0x91991261 NSApplicationMain + 1054
	31  ???                                 0x034c1180 0x0 + 55316864
	32  ???                                 0x034c10c8 0x0 + 55316680
	33  ???                                 0x004a7da0 0x0 + 4881824
	34  ???                                 0x004a7e37 0x0 + 4881975
	35  NSStringBoundsWithSizeCrash         0x0000d282 mono_jit_runtime_invoke + 722
	36  NSStringBoundsWithSizeCrash         0x001a436a mono_runtime_invoke + 170
	37  NSStringBoundsWithSizeCrash         0x001a6f01 mono_runtime_exec_main + 705
	38  NSStringBoundsWithSizeCrash         0x001a6111 mono_runtime_run_main + 929
	39  NSStringBoundsWithSizeCrash         0x00069995 mono_jit_exec + 149
	40  NSStringBoundsWithSizeCrash         0x0006bf13 mono_main + 9587
	41  NSStringBoundsWithSizeCrash         0x00002299 main + 441
	42  NSStringBoundsWithSizeCrash         0x000020a6 start + 54

Debug info from gdb:


=================================================================
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.
=================================================================
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-06-21 06:38:00 UTC
This is because BoundingRectWithSize has the wrong return type.

It has already been fixed (https://github.com/mono/maccore/commit/103eee5e927edb9e6c3cc37bb47af184fef2f662).

As a workaround you can call this instead:

RectangleF boundingRect;
MonoMac.ObjCRuntime.Messaging.RectangleF_objc_msgSend_stret_SizeF_UInt32_IntPtr (out boundingRect, textToDraw.Handle, new MonoMac.ObjCRuntime.Selector ("boundingRectWithSize:options:attributes:").Handle, textRect.Size, (UInt32) drawOptions, TitleStringDrawingAttributes.Handle);