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:
committed by
Copybara-Service
parent
230e2780de
commit
81ba9ec54a
@@ -45,23 +45,16 @@ GlfwCoreVideo::~GlfwCoreVideo() {
|
||||
CVDisplayLinkRelease(display_link_);
|
||||
}
|
||||
|
||||
void GlfwCoreVideo::EnqueueSwap() {
|
||||
void GlfwCoreVideo::WaitForDisplayRefresh() {
|
||||
std::unique_lock lock(mu_);
|
||||
second_buffer_has_content_ = true;
|
||||
}
|
||||
|
||||
void GlfwCoreVideo::WaitForSwap() {
|
||||
if (second_buffer_has_content_) {
|
||||
std::unique_lock lock(mu_);
|
||||
cond_.wait(lock, [this]() { return !this->second_buffer_has_content_; });
|
||||
}
|
||||
waiting_.store(true);
|
||||
cond_.wait(lock, [this]() { return !this->waiting_; });
|
||||
}
|
||||
|
||||
int GlfwCoreVideo::DisplayLinkCallback() {
|
||||
if (second_buffer_has_content_) {
|
||||
if (waiting_.load()) {
|
||||
std::unique_lock lock(mu_);
|
||||
Glfw().glfwSwapBuffers(window_);
|
||||
second_buffer_has_content_ = false;
|
||||
waiting_.store(false);
|
||||
cond_.notify_one();
|
||||
}
|
||||
return kCVReturnSuccess;
|
||||
|
||||
Reference in New Issue
Block a user