Bug 265 - ABI error wrt structures cause crashes on x86 (simulator)
Summary: ABI error wrt structures cause crashes on x86 (simulator)
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- critical
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 266 312 2293 ()
Depends on:
Blocks: 312 2059
  Show dependency tree
 
Reported: 2011-08-11 09:38 UTC by Jason Trahan
Modified: 2011-12-01 06:50 UTC (History)
7 users (show)

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

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 Jason Trahan 2011-08-11 09:38:04 UTC
When overriding the UITextField's Editing rect the application crashes. Even overriding and not making any changes as showing in Example 2 also causes a crash.

There seems to be a workaround which I found on stackoverflow but it doesn't appear anybody has reported this issue officially.

Workaround can be found here
http://stackoverflow.com/questions/5301675/monotouch-create-custom-uitextfield-and-override-methods

Example 1:
public override RectangleF EditingRect (RectangleF forBounds)
{
  return RectangleF.Inflate(forBounds, 5, 5); 
}

Example 2:
public override RectangleF EditingRect(RectangleF forBounds)
{
  return base.EditingRect(forBounds);
}

Workaround:
[Export("editingRectForBounds")]
public RectangleF EditingRectFix()
{
  var rect = base.EditingRect(this.Bounds);
  return RectangleF.Inflate(rect, -5, -5); // Not sure why I need negative numbers here
}

Stacktrace:

  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:26
  at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:31
  at MonoKeyboardTestProject.Application.Main (string[]) [0x00000] in /Volumes/Projects/MonoTouch/MonoKeyboardTestProject/MonoKeyboardTestProject/Main.cs:13
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   MonoKeyboardTestProject             0x000d0de8 mono_handle_native_sigsegv + 343
	1   MonoKeyboardTestProject             0x0000f74c mono_sigsegv_signal_handler + 322
	2   libSystem.B.dylib                   0x99da905b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   MonoKeyboardTestProject             0x0029fe59 monotouch_x86_double_abi_stret_trampoline + 144
	5   UIKit                               0x01d70d51 -[UITextField layoutSubviews] + 292
	6   QuartzCore                          0x031b1a5a -[CALayer layoutSublayers] + 181
	7   QuartzCore                          0x031b3ddc CALayerLayoutIfNeeded + 220
	8   QuartzCore                          0x031590b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
	9   QuartzCore                          0x0315a294 _ZN2CA11Transaction6commitEv + 292
	10  QuartzCore                          0x0315a46d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
	11  CoreFoundation                      0x00ea289b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
	12  CoreFoundation                      0x00e376e7 __CFRunLoopDoObservers + 295
	13  CoreFoundation                      0x00e001d7 __CFRunLoopRun + 1575
	14  CoreFoundation                      0x00dff840 CFRunLoopRunSpecific + 208
	15  CoreFoundation                      0x00dff761 CFRunLoopRunInMode + 97
	16  GraphicsServices                    0x0404e1c4 GSEventRunModal + 217
	17  GraphicsServices                    0x0404e289 GSEventRun + 115
	18  UIKit                               0x01ce2c93 UIApplicationMain + 1160
	19  ???                                 0x09eb4ed3 0x0 + 166416083
	20  ???                                 0x09eb4ca4 0x0 + 166415524
	21  ???                                 0x09eb42a4 0x0 + 166412964
	22  ???                                 0x09eb40fc 0x0 + 166412540
	23  ???                                 0x09eb424e 0x0 + 166412878
	24  MonoKeyboardTestProject             0x0000f507 mono_jit_runtime_invoke + 1332
	25  MonoKeyboardTestProject             0x001ed259 mono_runtime_invoke + 137
	26  MonoKeyboardTestProject             0x001ef940 mono_runtime_exec_main + 669
	27  MonoKeyboardTestProject             0x001eed2a mono_runtime_run_main + 843
	28  MonoKeyboardTestProject             0x000a3093 mono_jit_exec + 200
	29  MonoKeyboardTestProject             0x002a163d main + 4060
	30  MonoKeyboardTestProject             0x00002819 _start + 208
	31  MonoKeyboardTestProject             0x00002748 start + 40

Debug info from gdb:

dyld: could not load inserted library: /Users/Lunatik/Library/Application Support/iPhone Simulator/4.3/Applications/6FA37E53-04E7-4178-B12A-DEF0AEF25447/MonoKeyboardTestProject.app/monotouch-fixes.dylib


=================================================================
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 Sebastien Pouliot 2011-08-11 11:49:48 UTC
Could you attach a self-contained test case and also tell us which version of MonoTouch you're using ? Thanks!

p.s. you can share the test case with bug #266 :-)
Comment 2 Jason Trahan 2011-08-11 12:00:32 UTC
I'm using 4.0.4.1

------

[Register]
public class UICustomTextField: UITextField
{

	public UIRoundedTextField() { this.Initialize(); }		
	public UIRoundedTextField(RectangleF frame) : base(frame) { this.Initialize(); }
	public UIRoundedTextField(IntPtr handle) : base(handle) { this.Initialize();}		
	public UIRoundedTextField(NSCoder coder) : base(coder) { this.Initialize(); }		
	public UIRoundedTextField(NSObjectFlag flag) : base(flag) { this.Initialize(); }


	void Initialize() {}

	# Test case #1 only override this method
	public override RectangleF EditingRect(RectangleF forBounds)
	{
		return base.EditingRect(forBounds);
	}

	# Test case #2 override either or both methods for bug #266
	public override RectangleF TextRect(RectangleF forBounds)
	{
		return base.TextRect(forBounds);
	}
	

	public override RectangleF PlaceholderRect (RectangleF forBounds)
	{
		return base.PlaceholderRect (forBounds);
	}

}

var textField = new UITextField(new RectangleF(0, 0, 100, 26));
textField.PlaceHolder = "It's gonna crash here"; // For bug #266
Comment 3 Jason Trahan 2011-08-11 12:07:59 UTC
Heh. I forgot to rename the Constructors. Please name for your test case.
Comment 4 Sebastien Pouliot 2011-08-11 13:45:00 UTC
Confirmed on the simulator - but it works on the device (does it for you too ?)

Looks like an ABI issue wrt monotouch_x86_double_abi_stret_trampoline (which is is, like its name implies, x86 specific - the ARM devices use a different code path).
Comment 5 Jason Trahan 2011-08-11 15:31:51 UTC
Unfortunately I just started using MT so I'm still in evaluation mode so the simulator is all I can use at this time.
Comment 6 Sebastien Pouliot 2011-08-11 16:14:46 UTC
*** Bug 266 has been marked as a duplicate of this bug. ***
Comment 7 Sebastien Pouliot 2011-08-11 16:15:59 UTC
This is an ABI issue that only affect x86.
Comment 8 Sebastien Pouliot 2011-08-11 16:35:17 UTC
Overriding Bounds seems to work fine, e.g.

		public override RectangleF Bounds {
			get {
				Console.WriteLine ("get_Bounds");
				return base.Bounds;
			}
			set {
				Console.WriteLine ("set_Bounds");
				base.Bounds = value;
			}
		}

but the other (crashing cases) are overriding methods that return a structure *and* has a structure has it's parameter. I guess it explains why the crash was not (much) noticed before. e.g.

    public override RectangleF TextRect(RectangleF forBounds)
    {
	Console.WriteLine ("TextRect");
        return base.TextRect(forBounds);
    }

Crash occurs before reaching the method (so no C.WL).
Comment 10 Sebastien Pouliot 2011-08-18 10:18:29 UTC
*** Bug 312 has been marked as a duplicate of this bug. ***
Comment 11 Sebastien Pouliot 2011-08-18 10:19:33 UTC
bumping severity (second case found)
Comment 12 Rolf Bjarne Kvinge [MSFT] 2011-11-25 19:45:16 UTC
This has been fixed now. The first release after MT 5.1 or MT 5.0.3 (both are close to being released, so this fix won't be in them).
Comment 13 Rolf Bjarne Kvinge [MSFT] 2011-12-01 06:50:30 UTC
*** Bug 2293 has been marked as a duplicate of this bug. ***