Bug 14233 - TouchupInside event on button created on the fly causes monotouch to crash
Summary: TouchupInside event on button created on the fly causes monotouch to crash
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-08-26 06:40 UTC by Paul Johnson
Modified: 2013-08-27 07:55 UTC (History)
2 users (show)

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:

Description Paul Johnson 2013-08-26 06:40:18 UTC
I have created a list of strings from which I am creating a number of UIButtons that are added to a UIScrollView using the following code

y = 4;
t = 0;
foreach (string s in crops)
    UIButton btn = new UIButton(UIButtonType.RoundedRect);
    btn.Frame = new RectangleF(4, y, AppDelegate.Self.ScreenX - 8, 16);
    btn.SetTitleColor(UIColor.Blue, UIControlState.Normal);
    btn.SetTitle(s, UIControlState.Normal);
    btn.Tag = t;
    btn.TouchUpInside += (object sender, EventArgs e) => 
        UIButton but = (UIButton)sender;
        NavigationController.PushViewController(new myNewView(s[but.Tag]), true);
    y += 20;

The buttons are correctly added, but clicking any of them results in the following throwback

mono-rt: Stacktrace:

mono-rt:   at <unknown> <0xffffffff>

mono-rt:   at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>

mono-rt:   at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38

mono-rt:   at ftrack2ios.Application.Main (string[]) [0x0000a] in /Volumes/Developer/Developer/ftrack-2/iOS/ftrack2-ios/ftrack2-ios/Main.cs:18

mono-rt:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

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 2013-08-26 10:34:40 UTC
The `scrlView.AddSubview(btn);` should keep a reference to your button.

Can you attach a self-copntained test case that reproduce the issue ?
Comment 2 Paul Johnson 2013-08-27 04:47:23 UTC
No idea why a change for it to display the string should make it work, but it does. Further digging didn't show much, but it now works.

It's all rather confusing really…
Comment 3 Sebastien Pouliot 2013-08-27 07:55:20 UTC
> why a change for it to display the string 

Which string ? the button's title ? it should not matter.

If you can goback to the original (crash condition) and get me the app (or a test case) I'll have a look into it.