NSOpenGLView hang on CGLFlushDrawable

Originator:ePirat07
Number:rdar://37064579 Date Originated:January 31 2018, 12:26 PM
Status:Open Resolved:
Product:macOS + SDK Graphics & Imaging Product Version:10.13.4 Beta (17E139j)
Classification:Bug Reproducible:Always
 
Summary:
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.

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

Version/Build:
macOS High Sierra 10.13.4 Beta (17E139j)

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

Comments

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

https://gist.github.com/torarnv/a2da63f805d5b65ec0af0c0f11843c76

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:

https://gist.github.com/torarnv/b3f0ef8ead14fed8fd1765a0b0ecba2b

Attachments


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!