Bug 8711 - UITextField placed on UITableViewCell with ShouldReturn assigned crashes app
Summary: UITextField placed on UITableViewCell with ShouldReturn assigned crashes app
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.1.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-01 02:03 UTC by Andrew
Modified: 2012-12-06 04:08 UTC (History)
2 users (show)

Tags:
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 INVALID

Description Andrew 2012-12-01 02:03:59 UTC
I created cell with following code:
		private UITableViewCell getPasswordCell (string identifier)
		{
			var cell = new UITableViewCell (UITableViewCellStyle.Default, identifier) {
				SelectionStyle = UITableViewCellSelectionStyle.None
			};
			var field = new UITextField (new RectangleF(20,10,cell.Frame.Width-40, cell.Frame.Height-10)) {
				Placeholder = "Пароль",
				SecureTextEntry = true,
				AutocorrectionType = UITextAutocorrectionType.No,
				ReturnKeyType = UIReturnKeyType.Done,
			};
			field.ShouldReturn+= delegate {
				field.ResignFirstResponder();
				return true;
			};
			cell.AddSubview(field);
			
			return cell;
		}
And after I clicked on UITextField app craches with following stacktrace:

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) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at UKLiga.Application.Main (string[]) [0x00000] in /Users/m8rge/Projects/UKLiga/UKLiga/Main.cs:17
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   UKLiga                              0x000915ec mono_handle_native_sigsegv + 284
	1   UKLiga                              0x00006378 mono_sigsegv_signal_handler + 248
	2   libsystem_c.dylib                   0x9012759b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   UIKit                               0x02830306 -[UIResponder becomeFirstResponder] + 198
	5   UIKit                               0x029f3403 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 135
	6   UIKit                               0x029f5482 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2279
	7   UIKit                               0x029ec89a _UIGestureRecognizerSendActions + 139
	8   UIKit                               0x029eb9db -[UIGestureRecognizer _updateGestureWithEvent:] + 333
	9   UIKit                               0x029ed11f -[UIGestureRecognizer _delayedUpdateGesture] + 46
	10  UIKit                               0x029efd6d ___UIGestureRecognizerUpdate_block_invoke_0543 + 57
	11  UIKit                               0x029efcec _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 331
	12  UIKit                               0x029e7a68 _UIGestureRecognizerUpdate + 1348
	13  UIKit                               0x02754fc2 -[UIWindow _sendGesturesForEvent:] + 1283
	14  UIKit                               0x027554a3 -[UIWindow sendEvent:] + 98
	15  UIKit                               0x027333aa -[UIApplication sendEvent:] + 436
	16  UIKit                               0x02724cf8 _UIApplicationHandleEvent + 9874
	17  GraphicsServices                    0x04d0ddf9 _PurpleEventCallback + 339
	18  GraphicsServices                    0x04d0dad0 PurpleEventCallback + 46
	19  CoreFoundation                      0x012b4bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
	20  CoreFoundation                      0x012b4962 __CFRunLoopDoSource1 + 146
	21  CoreFoundation                      0x012e5bb6 __CFRunLoopRun + 2118
	22  CoreFoundation                      0x012e4f44 CFRunLoopRunSpecific + 276
	23  CoreFoundation                      0x012e4e1b CFRunLoopRunInMode + 123
	24  GraphicsServices                    0x04d0c7e3 GSEventRunModal + 88
	25  GraphicsServices                    0x04d0c668 GSEventRun + 104
	26  UIKit                               0x0272265c UIApplicationMain + 1211
	27  ???                                 0x0fd0c384 0x0 + 265339780
	28  ???                                 0x0fd0b180 0x0 + 265335168
	29  ???                                 0x0fd0a9a0 0x0 + 265333152
	30  ???                                 0x0fd0aa2f 0x0 + 265333295
	31  UKLiga                              0x0000a732 mono_jit_runtime_invoke + 722
	32  UKLiga                              0x0016c1ce mono_runtime_invoke + 126
	33  UKLiga                              0x00170354 mono_runtime_exec_main + 420
	34  UKLiga                              0x00175745 mono_runtime_run_main + 725
	35  UKLiga                              0x00067985 mono_jit_exec + 149
	36  UKLiga                              0x00203e92 main + 1986
	37  UKLiga                              0x00003735 start + 53

=================================================================
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 2012-12-02 13:07:30 UTC
There's not enough source code to be 100% sure but this is likely due to the GC disposing of the *managed* UITableViewCell that you return from your method.

If `cell` is only returned to native code (e.g. from GetCell) then it will be unreferenced and the GC can dispose (the managed side) of it. The native side will still exist and the app will be fine until it tries to callback into managed code (your event). 

More details and workaround in http://stackoverflow.com/a/12353010/220643
Comment 2 Andrew 2012-12-06 04:08:56 UTC
Yes, you right