New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSBezierPath should not check for UI thread #5234

praeclarum opened this Issue Dec 5, 2018 · 3 comments


None yet
3 participants

praeclarum commented Dec 5, 2018

NSBezierPaths are used throughout Cocoa for rendering on background threads in addition to foreground. Currently they throw when used in a background thread. This is wrong.

Steps to Reproduce

  1. Create a background thread
  2. NSBezierPath.FromOvalInRect (new CGRect (0, 0, 100, 100))

Expected Behavior

Path is created.

Actual Behavior

UI thread consistency exception is thrown.


=== Visual Studio Enterprise 2017 for Mac ===

Version 7.7 (build 1868)
Installation UUID: 4ba352e1-73e8-4dab-a9db-28012ca05af8
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac (master / eeaeb7e6)

	Package version: 516000221

=== Mono Framework MDK ===

	Mono (2018-06/b63e5378e38) (64-bit)
	Package version: 516000221

=== NuGet ===


=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks
SDK Versions:
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)
Hash: 5ef73d34
Build date: 2018-11-21 00:03:25-0500

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: 5ef73d34
Branch: d15-9
Build date: 2018-11-21 00:03:24-0500

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/fak/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		7.0 (API level 24)
		7.1 (API level 25)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 26.0.2
SDK Build Tools Version: 26.0.3

Java SDK: /Users/fak/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:

=== Android Device Manager ===

Hash: 06ceaea1

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 707001868
Git revision: 8bcdfa96d67c8c88dc45728cc968a2f84b55322f
Build date: 2018-11-22 12:19:29+00
Build branch: release-7.7
Xamarin extensions: d66dbedcda237cd9b546abfecfeecafba6f8e3cb

=== Operating System ===

Mac OS X 10.14.1
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Fri Oct  5 19:41:49 PDT 2018
    root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

MSBuild Editor 2.1.0

This comment has been minimized.


spouliot commented Dec 6, 2018

Thread safety documentation tends to be limited and something incorrect. We'll check them against Apple's Main Thread Checker and disable the thread check if no assertion occurs. It might not be 100% accurate but, at least, it will be consistent with the results from Xcode.


This comment has been minimized.


spouliot commented Dec 6, 2018

- (void)viewDidLoad {
    [super viewDidLoad];
    dispatch_async(dispatch_get_global_queue(0,0), ^{
        [NSBezierPath bezierPathWithOvalInRect:CGRectZero];
        // known to fail
        NSLog (@"%@", [NSView new]);

shows that NSBezierPath calls does not trigger MTA while trying to create a new NSView does.

Main Thread Checker: UI API called on a background thread: -[NSView init]
PID: 75924, TID: 25065069, Thread name: (none), Queue name:, QoS: 0

@dalexsoto dalexsoto self-assigned this Dec 6, 2018

dalexsoto added a commit to dalexsoto/xamarin-macios that referenced this issue Dec 6, 2018

[AppKit] Adds some [ThreadSafe] to reported cases
Fixes xamarin#5233
Fixes xamarin#5234
Fixes xamarin#5235

The following selectors are thread safe:

* NSFont fontWithName:size:
* NSBezierPath bezierPathWithOvalInRect:
* NSString drawAtPoint:withAttributes:

dalexsoto added a commit that referenced this issue Dec 7, 2018


This comment has been minimized.

praeclarum commented Dec 7, 2018

Thanks @dalexsoto for the quick response! And thanks for making it class level, I should have mentioned that all these APIs are thread safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment