Cocoa: Fix call to NSWindow from non-main threads

glfwSwapBuffers may be called by any thread but NSWindow may not.

Bug introduced by c3ca88055f and reported
by @crujose.
This commit is contained in:
Camilla Löwy 2020-04-30 22:12:21 +02:00
parent cab41529da
commit 949275bbed
3 changed files with 10 additions and 1 deletions

View File

@ -121,6 +121,7 @@ typedef struct _GLFWwindowNS
id layer;
GLFWbool maximized;
GLFWbool occluded;
GLFWbool retina;
// Cached window properties to filter out duplicate events

View File

@ -322,6 +322,14 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
_glfwInputWindowFocus(window, GLFW_FALSE);
}
- (void)windowDidChangeOcclusionState:(NSNotification* )notification
{
if ([window->ns.object occlusionState] & NSWindowOcclusionStateVisible)
window->ns.occluded = GLFW_FALSE;
else
window->ns.occluded = GLFW_TRUE;
}
@end

View File

@ -51,7 +51,7 @@ static void swapBuffersNSGL(_GLFWwindow* window)
// HACK: Simulate vsync with usleep as NSGL swap interval does not apply to
// windows with a non-visible occlusion state
if (!([window->ns.object occlusionState] & NSWindowOcclusionStateVisible))
if (window->ns.occluded)
{
int interval = 0;
[window->context.nsgl.object getValues:&interval