Question about CGLLockContext

Hi Jules, I noticed that at some point (perhaps a couple years ago unfortunately) you added a "Locker" struct to the OS X OpenGL code which calls the functions CGLLock/UnlockContext.  And in OpenGLContext::renderFrame, you use the Locker around any GL drawing code.

Do you remember what purpose this serves?  Does it prevent some kind of multithreading problem?  At the moment I'm dealing with an issue like this one: http://www.cocoabuilder.com/archive/cocoa/107699-nsopenglview-from-second-nsthread.html, where resizing my OpenGL window  by dragging the corner causes a crash (and this window is rendered in a secondary thread).

It's a difficult crash to reproduce though, so I'm not exactly sure when I've fixed it and when I haven't, which is why I'm asking what you remember about the need for the CGLLock/UnlockContext functions.

Many thanks for any help in understanding this.

Yes - I can't remember the exact details but I think it was because other non-JUCE code could run on the OSX message thread while the GL was being rendered, and that caused some kind of race or corruption problem. It was certainly necessary..

Ok, after doing some more research, it looks like this is the issue: "When you use an NSOpenGLView object with OpenGL calls that are issued from a thread other than the main one, you must set up mutex locking." ( https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html#//apple_ref/doc/uid/TP40001987-CH409-SW7)

And this topic on the forums here is relevant: http://www.juce.com/forum/topic/opengl-deadlocks-mac

So I guess it all makes sense now.  Hopefully I won't get any more crashes by using the lock functions.