NSOpenGLView hang on CGLFlushDrawable

Number:rdar://37064579 Date Originated:January 31 2018, 12:26 PM
Status:DUPLICATE OF 32963679 Resolved:
Product:macOS + SDK Graphics & Imaging Product Version:10.13.4 Beta (17E139j)
Classification:Bug Reproducible:Always
When using multiple NSOpenGLViews and rendering content for them in a background thread, it hangs on the CGLFlushDrawable call on the context, when the windows contentView is layer backed.

Steps to Reproduce:
1. Create a subclass of NSOpenGLView with rendering on a different thread, like by using a CVDisplayLink.
2. Make the contentView of a NSWindow layer backed and add multiple (three or four) subviews with the subclassed NSOpenGLView class.
3. Start the application

(The sample project attached is already setup correctly for this scenario, it is only necessary to switch to the OS X variant and build it, then run it and it will hang.)

Expected Results:
The content in the OpenGL views should render fine, no hangs should happen.

Actual Results:
The program hangs on a call to CGLFlushDrawable.

The same happens when using the Objective C flushBuffer method on the NSOpenGLContexts.

macOS High Sierra 10.13.4 Beta (17E139j)

MacBook Pro (Retina, 13", Ende 2013)
2,4 GHz Intel Core i5
Intel Iris 1536 MB


Another reproducer, where one thread holding a lock on its own context using CGLLockContext, prevents the other thread from flushing:


Here's an example that reproduces the issue. Note that there are two separate NSWindows, each with their own GLView, each with their own NSOpenGLContext, rendered to by two separate (CVDisplayLink) threads, and it still deadlocks:



Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!