Bug 37174 - Bug in UINavigationBar.Appearance.SetTitleTextAttributes(att) Cycle 6 SR 1 ALPHA
Summary: Bug in UINavigationBar.Appearance.SetTitleTextAttributes(att) Cycle 6 SR 1 ALPHA
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2015-12-20 18:05 UTC by Neal
Modified: 2017-07-26 14:17 UTC (History)
3 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 NOT_REPRODUCIBLE

Description Neal 2015-12-20 18:05:24 UTC
Hello,

I'm testing the ALPHA channel for C6 SR1 and there may be a bug.  I'm getting random crashes on my iPad testers on the insights URL below which has my code of:

UITextAttributes att = new UITextAttributes()
{
	TextColor = UIColor.White,
	TextShadowColor = apdlTextHeaderShadowColor()
};
UINavigationBar.Appearance.SetTitleTextAttributes(att);

Insights Hit:

https://insights.xamarin.com/app/APDL3b54/issues/1753

Which has:

System.IndexOutOfRangeExceptionIndex was outside the bounds of the array.

System.Object.virt_stelemref_class(intptr, object)(wrapper stelemref)
UIKit.UITextAttributes.ToDictionary()
UIKit.UINavigationBar.UINavigationBarAppearance.SetTitleTextAttributes(UITextAttributes attributes)
APDL.AppearanceBase.Config()
APDL.APDLAppearance.Config()
APDL.AppDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
UIKit.UIApplication.UIApplicationMain(int, string[], intptr, intptr)(wrapper managed-to-native)
UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName)
APDL.Application.Main(string[] args)



=== Xamarin Studio ===

Version 5.10.2 (build 49)
Installation UUID: 73513e37-5013-428d-8378-0897497f2380
Runtime:
	Mono 4.2.2 (explicit/7b87787)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402020010

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.2 (9548)
Build 7C68

=== Xamarin.Mac ===

Version: 2.4.1.5 (Business Edition)

=== Xamarin.iOS ===

Version: 9.4.1.12 (Business Edition)
Hash: 78c6cd3
Branch: master
Build date: 2015-12-17 18:29:42-0500

=== Xamarin.Android ===

Version: 6.0.1.5 (Business Edition)
Android SDK: /Users/Neal/Applications/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4.0
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Build Information ===

Release ID: 510020049
Git revision: deed4cd240ff3611c8742bbc62296e207f46173d
Build date: 2015-12-17 11:13:36-05
Xamarin addins: 8bd975e7b465f6fe812b64d736f3b7e8c1a79a3e
Build lane: monodevelop-lion-cycle6-c6sr1

=== Operating System ===

Mac OS X 10.11.2
Darwin iMACRH.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 1 Neal 2015-12-21 02:29:18 UTC
Changing the appearance code to that below solved the problem but you may want to help someone from having this issue going forward:

UINavigationBar.Appearance.TitleTextAttributes = (new UIStringAttributes() { ForegroundColor = UIColor.White });
Comment 2 Sebastien Pouliot 2015-12-21 16:31:51 UTC
@Neal thanks for the details. I was not able to reproduce and there was no direct changes to UITextAttributes in the SR1 alpha.

OTOH the UITextAttributes code is not thread safe*, is it possible that it can be used/modified across multiple threads ?

* UIStringAttributes is thread safe
Comment 3 Neal 2015-12-21 16:34:04 UTC
Hi Sebastien, it's very possible!  Glad to know...just thought I'd bring this to your attention as I have not had this hit in the past and it's a new hit for C6 ALPHA SR1.  i.e. this has not come up before and this code has been there for over a year.
Comment 4 Sebastien Pouliot 2015-12-23 14:36:20 UTC
Fixed in maccore/master 600950385601751e112e37912fbed51066ef1e05

The stack trace shows this happens at startup and this is a place where the order of things can change a lot. I'm not 100% certain (can't be without a test case) but the fact that UITextAttributes was _not_ thread safe could lead to IndexOutOfRangeException

@Neal you should continue using UIStringAttributes as it's more future proof (available for watchOS and tvOS) and already thread-safe.
Comment 5 Neal 2015-12-25 13:35:37 UTC
Sebastian,

I had another crash from a UITextAttributes usage I want you to be aware of, same build as above (before using the custom build you sent me yesterday).  It is actually in a ViewDidLoad of a UITableViewController, here is the code:

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    UITextAttributes att = new UITextAttributes()
    {
        Font = UIFont.SystemFontOfSize(14f)
    };
    PositionSegmentedControl.SetTitleTextAttributes(att, UIControlState.Normal);
	PositionSegmentedControl.TintColor = UIColor.White;
}

Here are the Insights hits:

https://insights.xamarin.com/app/APDL3b54/issues/1754

https://insights.xamarin.com/app/APDL3b54/issues/1801

I don't know that UIStringAttributes is an available option to set the font on a UISegmentControl but I was able to just comment this out as in the end the code was not needed.

FYI

Neal
Comment 6 Kevin Mullins 2017-07-26 14:17:54 UTC
Thanks so much for taking the time to submit this report! I attempted to reproduce this issue based on the bug description with the latest Xamarin.iOS 10.12.0.14, and I was unable to hit the problem. If this issue is still occurring for you, please reopen this report and attach a project that reproduces the issue, ideally starting with a new template project and then adding just the code necessary to demonstrate the issue.