Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 25810 [details]
It's impossible to use `NSOpenGLContext` from any threads except the Main UI thread.
NSOpenGLContext.FlushBuffers(), NSOpenGLContext.CGLContext.Lock() and some other methods throw an exception:
"AppKit Consistency error: you are calling a method that can only be invoked from the UI thread."
But this is not true.
According to the Apple documentations (and samples) we are allowed and we are forced to invoke this methods from other threads (e.g. due to the DisplayLink callback)
Assembly Browser shows the cause of that exception in some CompilerGenerated methods:
It seems that this guard is unnecessary and moreover, harmful.
## Steps to reproduce
1. Open attached TestGL demo project in Visual Studio.
2. In order to see an exception from background threads make some settings in Visual Studio for Mac (Run -> New Exception Catchpoint, choose "When an exception is thrown" for 'System.Exception' and set 'Include Subclasses' checkbox, press Create)
3. Start Debugging
4. Observe thrown exception as a result of invoking _mainContext.CGLContext.Lock() (_mainContext.CGLContext.FlushBuffer and so on)
Visual Studio Community 2017 for Mac
Version 7.2.2 (build 11)
Mono 22.214.171.124 (2017-06/1f4613aa1ac) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Package version: 504010006
NuGet Version: 126.96.36.19945
Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks
Apple Developer Tools
Xcode 9.1 (13532)
Version: 188.8.131.52 (Visual Studio Community)
Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
Thanks for the information!
The threading checks are debug helpers, i.e. they are removed from release builds (by the managed linker), unless extra arguments are given to mtouch, as they have a performance impact on applications (e.g. when used in tight loops).
We acknowledge this enhancement request, therefore marked it as CONFIRMED.
However, we need to do a full API review on NSOpenGLContext to not dismiss cases
where the UI thread check is valid.
You can workaround this by disabling the check before the NSOpenGLContext.FlushBuffers() call (and re-enabling it afterward). E.g. something like:
NSApplication.CheckForIllegalCrossThreadCalls = false;
NSApplication.CheckForIllegalCrossThreadCalls = true;
Hope this helps!
OpenGL context are restricted to a single thread - but it does not have to be the main thread.
The current check is excessive.
Merged in master https://github.com/xamarin/xamarin-macios/commit/3355fdfc6e06d56b9b6c741335efeb9d47f971f9