[MonoTouch] SDK 5 issue

Jeff Stedfast jeff at xamarin.com
Tue Oct 18 15:32:45 EDT 2011


Hi Sergio,

>From looking at the code, I'm guessing that the problem is that your
MyUIOperation is getting GC'd. You only hold a reference to the latest one
added, but if you click multiple times, you might add multiple operations to
your queue and all but the last one added will have been GC'd.

You might have to keep your own managed (C#) queue of NSOperations and have
.Main() remove itself from your _queue.

Hope that helps,

Jeff

On Tue, Oct 18, 2011 at 12:24 PM, Sergio Fadda <sergio.fadda at logobject.ch>wrote:

> Ok, after solving the issue in the topic, I finally isolated the problem I
> have in my project. Should be a synchronization issue with the GC. Here's
> the app that replicate the issue:
>
> using System;
> using System.Drawing;
> using MonoTouch.Foundation;
> using MonoTouch.UIKit;
>
> namespace MTFailure
> {
> 	public class Application
> 	{
> 		static void Main (string[] args)
> 		{
> 			UIApplication.Main (args, null, "AppDelegate");
> 		}
> 	}
> 	
> 	public class MyUIOperation : NSOperation
> 	{
> 		private NSAction _action;
> 		
> 		public MyUIOperation(NSAction action)
> 		{
> 			_action = action;
> 		}
> 		
> 		public override void Main ()
> 		{
> 			// Execute these actions in the main thread since it's a UI manipulation
> 			InvokeOnMainThread(_action);
> 		}
> 	}
> 	
> 	[Register("AppDelegate")]
> 	public class AppDelegate : UIApplicationDelegate
> 	{
> 		private MonoTouch.UIKit.UIWindow __mt_window;
> 		private UINavigationController _navCtrl;
> 		
> 		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
> 		{
> 			__mt_window = new UIWindow(UIScreen.MainScreen.Bounds);
> 			__mt_window.BackgroundColor = UIColor.White;
> 			
> 			_navCtrl = new UINavigationController();
> 			_navCtrl.PushViewController(CreatePage(), true);
> 			
> 			__mt_window.AddSubview(_navCtrl.View);
> 			__mt_window.MakeKeyAndVisible ();
> 	
> 			return true;
> 		}
> 		
> 		protected UIViewController CreatePage()
> 		{
> 			UIViewController result = new UIViewController();
> 			UIView pageView = new UIView(UIScreen.MainScreen.Bounds);
> 			
> 			UIButton btn = UIButton.FromType(UIButtonType.RoundedRect);
> 			btn.Frame = new RectangleF(0, 50, 320, 37);
> 			btn.TouchUpInside += HandleBtnTouchUpInside;
> 			btn.SetTitle("Touch me!!!", UIControlState.Normal);
> 			pageView.AddSubview(btn);
> 			
> 			result.View = pageView;
> 			
> 			return result;
> 		}
>
> 		private NSOperationQueue _queue = new NSOperationQueue();
> 		private NSOperation _op;
> 		
> 		void HandleBtnTouchUpInside (object sender, EventArgs e)
> 		{
> 			// Enqueue the operation and let the os to handle it in another thread
> 			_op = new MyUIOperation(DeferredAction);
> 			_queue.AddOperation(_op);
> 		}
> 		
> 		private UIViewController _subCtrl;
> 		
> 		private void DeferredAction()
> 		{
> 			_navCtrl.PushViewController(CreatePage (), true);
> 		}
>
> 		// This method is required in iPhoneOS 3.0
> 		public override void OnActivated (UIApplication application)
> 		{
> 		}
> 	}
> }
>
> That is, a simple navigation app with a button in a view; the action of the
> button must be deferred and usually is a UI manipulation; running the
> application and pressing the button a variable number of times the
> application crashes and displays the following message:
>
> Stacktrace:
>
>
> Native stacktrace:
>
> 	0   MTFailure                           0x000d5c18 mono_handle_native_sigsegv + 408
> 	1   MTFailure                           0x00012fcf mono_sigsegv_signal_handler + 351
> 	2   libsystem_c.dylib                   0x9435859b _sigtramp + 43
> 	3   ???                                 0xffffffff 0x0 + 4294967295
> 	4   libobjc.A.dylib                     0x0199dc09 _class_getVariable + 99
> 	5   libobjc.A.dylib                     0x0199415f object_getInstanceVariable + 56
> 	6   MTFailure                           0x002cc543 monotouch_release_trampoline + 419
> 	7   Foundation                          0x00747d16 __release_object_op + 37
> 	8   libdispatch.dylib                   0x0214cc7b _dispatch_async_f_redirect_invoke + 146
> 	9   libdispatch.dylib                   0x0214c4e6 _dispatch_worker_thread2 + 284
> 	10  libsystem_c.dylib                   0x94302b24 _pthread_wqthread + 346
> 	11  libsystem_c.dylib                   0x943046fe start_wqthread + 30
>
> =================================================================
> 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.
> =================================================================
>
> This issue is present only with iOS 5 (both device and simulator), but in
> iOS 4.3 works fine!
>
> What's wrong now?
> Thanks,
> Sergio
> ------------------------------
> View this message in context: Re: SDK 5 issue<http://monotouch.2284126.n4.nabble.com/SDK-5-issue-tp3912223p3915935.html>
>
> Sent from the MonoTouch mailing list archive<http://monotouch.2284126.n4.nabble.com/>at Nabble.com.
>
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111018/b8757cdb/attachment.html 


More information about the MonoTouch mailing list