elvman wrote on Sunday, March 01, 2015:
If you open a NSOpenPanel on OSX in a GLFW app, the OpenGL context is lost and glfwMakeContextCurrent is not setting it back. Try running the following funvtion anywhere in a GLFW app.
void testOpenPanel() { NSOpenPanel* openPanel = [NSOpenPanel openPanel]; openPanel.title = @"Choose a .JSON file"; openPanel.showsResizeIndicator = YES; openPanel.showsHiddenFiles = NO; openPanel.canChooseDirectories = NO; openPanel.canCreateDirectories = YES; openPanel.allowsMultipleSelection = NO; openPanel.allowedFileTypes = @[@"json"]; [openPanel beginWithCompletionHandler:^(NSInteger result) { if (result == NSModalResponseOK) { NSURL *selection = openPanel.URLs[0]; NSString* path = [selection.path stringByResolvingSymlinksInPath]; NSLog(@"Path: %@", path); } }]; }
A quick workaround is placing the following code in main loop:
NSOpenGLContext* context = glfwGetNSGLContext(window); [context makeCurrentContext]
This can also be done with GLFW functions:
glfwMakeContextCurrent(nullptr); glfwMakeContextCurrent(window);
Also glfwGetCurrentContext returns GLFW’s context although NSOpenPanel has switched it to a different one. I suggest checking current context every frame and change it back to GLFW’s one if it has changed.
Full source code is available here: http://pastebin.com/6PxJp9Ak