Bug 34271 - NSShadow throws exception when used on non-UI thread
Summary: NSShadow throws exception when used on non-UI thread
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 8.10
Hardware: Macintosh Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-25 04:14 UTC by Mark Woollard
Modified: 2017-07-24 23:27 UTC (History)
3 users (show)

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


Attachments
Solution demonstrating defect (9.27 KB, application/zip)
2017-07-24 22:39 UTC, Larry O'Brien
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 for Bug 34271 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Mark Woollard 2015-09-25 04:14:13 UTC
Accessing properties of NSShadow from background threads throws non-UI thread exception. This would appear to be same mis-conception as with NSMutableParagrahStyle (see https://bugzilla.xamarin.com/show_bug.cgi?id=28032). My understanding is that the issue with NSMutableParagraphStyle is fixed internally but am not clear as to whether its in iOS 9 release or not - we have had to hold off on this release due to other issues. What is the status with NSShadow, was that addressed at the same time or not yet fixed?
Comment 1 Sebastien Pouliot 2015-09-25 09:05:04 UTC
Sadly thread safety is not something that is well documented by Apple
for their API. It's even not uncommon to find Apple own's sample not
correctly using some API.

If the thread safety rules are not provided for an API then the 
following rules are applied:

1. UIKit is considered thread unsafe

> For the most part, use UIKit classes only from your app’s main thread.
> This is particularly true for classes derived from UIResponder or 
> that involve manipulating your app’s user interface in any way. 

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKit_Framework/


2. Some exceptions are listed, globally, in this document 

https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-SW1


3. Any other document (e.g. WWDC videos) that we can double-check
with Apple (radar) to confirm it's thread safe.


Te misuse of some API on incorrect threads can lead to hard to
find/duplicate issues inside application code. This is why XI has,
by default, added thread checks inside the (debug only) builds.

We'll review the case for NSShadow and see if we should treat it 
as thread-safe (or not) by default. At the moment this type is not
considered as thread-safe.

Note that you can totally disable this feature  globally or locally: 
http://tirania.org/monomac/archive/2012/Sep-10.html
Comment 2 Mark Woollard 2015-09-25 10:39:25 UTC
NSShadow can be applied to NSAttributedString/NSMutableAttributedString - the latter are thread safe and thus NSShadow would have to be to be usable. However the article you reference is very useful and I can code work around for now.
Comment 3 Larry O'Brien 2017-07-24 22:39:56 UTC
Created attachment 23769 [details]
Solution demonstrating defect

Attached solution attempts to access NSShadow from a background thread, in which case it throws (which is caught and written to console). Does it again from UI thread, in which case it doesn't throw.
Comment 4 Larry O'Brien 2017-07-24 22:40:35 UTC
Marking as "enhancement"
Comment 5 Larry O'Brien 2017-07-24 22:41:15 UTC
Thanks so much for taking the time to submit this report! I can confirm using the latest Xamarin.iOS 10.12.0.14 I am able to reproduce this issue. Marking this report as CONFIRMED.