Ver código fonte

Cocoa: Fix call to NSWindow from non-main threads

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

Bug introduced by c3ca88055f7c2c8b02b38cb90fc1989990552977 and reported
by @crujose.

(cherry picked from commit 949275bbedaa58a5399c6ce5276adc190ae6a16b)
Camilla Löwy 5 anos atrás
pai
commit
6e01359e36
3 arquivos alterados com 10 adições e 1 exclusões
  1. 1 0
      src/cocoa_platform.h
  2. 8 0
      src/cocoa_window.m
  3. 1 1
      src/nsgl_context.m

+ 1 - 0
src/cocoa_platform.h

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

+ 8 - 0
src/cocoa_window.m

@@ -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
 
 

+ 1 - 1
src/nsgl_context.m

@@ -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