Fix a rare crash when running simulate on macOS.

The bug was introduced in 2f0fb1e4ef. The glfwSwapBuffers call should occur on the main UI thread, not the CoreVideo DisplayLink thread.

PiperOrigin-RevId: 517172202
Change-Id: I2491f2194765019748198cd0cc61ca9263331b01
This commit is contained in:
Saran Tunyasuvunakool
2023-03-16 11:05:38 -07:00
committed by Copybara-Service
parent 230e2780de
commit 81ba9ec54a
3 changed files with 11 additions and 21 deletions
+4 -3
View File
@@ -19,6 +19,7 @@
#error "This header only works on macOS."
#endif
#include <atomic>
#include <condition_variable>
#include <mutex>
@@ -37,8 +38,8 @@ class GlfwCoreVideo {
public:
GlfwCoreVideo(GLFWwindow* window);
~GlfwCoreVideo();
void EnqueueSwap();
void WaitForSwap();
void WaitForDisplayRefresh();
int DisplayLinkCallback();
void UpdateDisplayLink();
@@ -46,7 +47,7 @@ class GlfwCoreVideo {
GLFWwindow* window_;
CVDisplayLinkRef display_link_;
bool second_buffer_has_content_;
std::atomic_bool waiting_;
std::mutex mu_;
std::condition_variable cond_;
};