Bug 1920 - Crash in iOS 5
Summary: Crash in iOS 5
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 1.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-07 17:07 UTC by jwcreech
Modified: 2012-01-18 15:13 UTC (History)
3 users (show)

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


Attachments
TableView and CustomCellView where crash occurs. (14.76 KB, application/octet-stream)
2011-11-11 11:29 UTC, jwcreech
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 NOT_REPRODUCIBLE

Description jwcreech 2011-11-07 17:07:18 UTC
I have an app that works fine in IOS 4. When users upgrade to iOS 5, that app
crashes.

The app crashes in a Table View, I have a custom cell view. When the user
clicks a on a cell, the app crashes. Any help would be appreciated. If
anyone knows if Xamarin is coming out with an update that repairs this as
well, please let me know. Here is the error message I receive on crash:

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) [0x00042]
in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
 at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in
/Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34
 at RxNTClient4.Application.Main (string[]) [0x00000] in
/Users/rxnt/Documents/Projects/RxNTClient4/RxNTClient4/Main.cs:28
 at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object
(object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

       0   RxNTClient4                         0x000e1108
mono_handle_native_sigsegv + 408
       1   RxNTClient4                         0x00011e8f
mono_sigsegv_signal_handler + 351
       2   libSystem.B.dylib                   0x954b205b _sigtramp + 43
       3   ???                                 0xffffffff 0x0 + 4294967295
       4   UIKit                               0x01d061b5 -[UIControl
sendAction:to:forEvent:] + 67
       5   UIKit                               0x01d08647 -[UIControl(Internal)
_sendActionsForEvents:withEvent:] + 527
       6   UIKit                               0x01d071f4 -[UIControl
touchesEnded:withEvent:] + 458
       7   UIKit                               0x01f02987
_UIGestureRecognizerSortAndSendDelayedTouches + 3609
       8   UIKit                               0x01f030fc
_UIGestureRecognizerUpdateObserver + 927
       9   CoreFoundation                      0x00e8efbb
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
       10  CoreFoundation                      0x00e240e7 __CFRunLoopDoObservers +
295
       11  CoreFoundation                      0x00decbd7 __CFRunLoopRun + 1575
       12  CoreFoundation                      0x00dec240 CFRunLoopRunSpecific +
208
       13  CoreFoundation                      0x00dec161 CFRunLoopRunInMode + 97
       14  GraphicsServices                    0x03f4c268 GSEventRunModal + 217
       15  GraphicsServices                    0x03f4c32d GSEventRun + 115
       16  UIKit                               0x01c8642e UIApplicationMain + 1160
       17  ???                                 0x07feea34 0x0 + 134146612
       18  ???                                 0x07fee900 0x0 + 134146304
       19  ???                                 0x07fee1f8 0x0 + 134144504
       20  ???                                 0x07fee144 0x0 + 134144324
       21  ???                                 0x07fee1cf 0x0 + 134144463
       22  RxNTClient4                         0x00011bdf mono_jit_runtime_invoke
+ 1407
       23  RxNTClient4                         0x0022020a mono_runtime_invoke +
170
       24  RxNTClient4                         0x00222f41 mono_runtime_exec_main +
705
       25  RxNTClient4                         0x00222151 mono_runtime_run_main +
929
       26  RxNTClient4                         0x000ad7cf mono_jit_exec + 239
       27  RxNTClient4                         0x002f420a main + 5194
       28  RxNTClient4                         0x00003435 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.
=================================================================


I'm not sure yet, but I just noticed while I was writing this that this may be a version of bug 134 http://bugzilla.xamarin.com/show_bug.cgi?id=134
Comment 1 Zoltan Varga 2011-11-08 12:22:05 UTC
-> mt.
Comment 2 Sebastien Pouliot 2011-11-08 13:55:37 UTC
You're right it does looks like #134. This generally means that a managed object is being collected because there is not reference to it inside your application (so the GC consider it unused and frees it). 

The current* fix is to ensure you're keeping a reference to this object as long as it can be used (e.g. indirectly by native side of the control). There are many duplicate and a link (stackoverflow) that describe this in more details. If you need more help then please attach your code to the bug report and we'll review it.

* we're looking into ways (for future releases) to hide this complexity from developers
Comment 3 jwcreech 2011-11-11 11:29:33 UTC
Created attachment 878 [details]
TableView and CustomCellView where crash occurs.

I tried pulling all of the cell references out storing them in an array in PatientDrugSearchPage.xib.cs. I am getting a different crash:

Unhandled Exception: System.Exception: Selector invoked from objective-c on a managed object that has been GC'ed ---> System.MissingMethodException: No constructor found for MonoTouch.UIKit.UIControlEventProxy::.ctor(System.IntPtr)
  at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x000f1] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:280 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:234 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:229 
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:197 
  --- End of inner exception stack trace ---
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x0002e] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:200 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (IntPtr ptr) [0x0001f] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:244 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObjectWrapped (IntPtr ptr) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:261 
  at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetNSObjectWrapped (intptr)
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34 
  at RxNTClient4.Application.Main (System.String[] args) [0x00000] in /Users/rxnt/Documents/Projects/RxNTClient4/RxNTClient4/Main.cs:28 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Selector invoked from objective-c on a managed object that has been GC'ed ---> System.MissingMethodException: No constructor found for MonoTouch.UIKit.UIControlEventProxy::.ctor(System.IntPtr)
  at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x000f1] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:280 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:234 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:229 
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:197 
  --- End of inner exception stack trace ---
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x0002e] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:200 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject (IntPtr ptr) [0x0001f] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:244 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObjectWrapped (IntPtr ptr) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:261 
  at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetNSObjectWrapped (intptr)
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34 
  at RxNTClient4.Application.Main (System.String[] args) [0x00000] in /Users/rxnt/Documents/Projects/RxNTClient4/RxNTClient4/Main.cs:28 

Application Terminated

I guess the next step is to pull out all of the UI button references, and put them into arrays in the same class, as well as the event handlers? I'm not sure exactly how to do that. Any help would be appreciated.
Comment 4 Sebastien Pouliot 2011-11-11 13:43:32 UTC
I cannot build the code as supplied so I can only offer suggestions. I strongly suspect GetCell is (one of) your problem.

			public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
			{
				UITableViewCell cell = tableView.DequeueReusableCell("drugCell");
// the above value of 'cell' is not used before the variable is re-assigned
				MyCustomDrugCellViewController cellC = null;
				cellC = new MyCustomDrugCellViewController();
// 'cellC' is created in a local variable - the GC is allowed to dispose it once nothing else use it
				NSBundle.MainBundle.LoadNib("MyCustomDrugCellViewController", cellC, null);
				cell = cellC.drugCell;
// 'cell' is a local variable too, when nothing reference 'cell' then it (and 'cellC') can be disposed
				
				if (mtvc.cellArray != null) 
				{
					cell = mtvc.cellArray[indexPath.Row];
// 'cell' is re-assigned here, that 'cell' is referenced elsewhere so it could be alive longer
				}
				return cell;
// 'cell' is returned (this is being called from native code) but never assigned to something outside the local variable, at this stage (unless another 'cell' was assigned in the previous if condition, the GC is allowed to dispose it
			}

The code is a bit complex but, in general, you should keep a reference to any 'cell' you create inside GetCell (so the managed representation will exists as long as the native one you're returning). e.g. add them inside a List<UITableViewCell> for any cell you cannot reuse.

You might also want to check MonoTouch.Dialog since it makes working with tables a lot easier.
https://github.com/migueldeicaza/MonoTouch.Dialog

p.s. remove the NEEDINFO status when you supply an answer - it makes it easier to spot the issue was updated (for people not on the c.c. list).
Comment 5 jwcreech 2012-01-18 15:13:15 UTC
Yea I made reference to all of the cells from the parent class. It worked for me. Thanks.