cocoadisplay: Fix crash with threading-model on newer macOS versions

Updates the context on the main thread instead of the draw thread now. If render_frame happens to run while the context needs updating, it will skip the frame.

Fixes #1286
This commit is contained in:
rdb 2022-10-29 20:51:05 +02:00
parent 4c6df54d6f
commit 4cf8187df7

View File

@ -207,8 +207,13 @@ begin_frame(FrameMode mode, Thread *current_thread) {
// Update the context if necessary, to make it reallocate buffers etc.
if (_context_needs_update) {
[cocoagsg->_context update];
_context_needs_update = false;
if ([NSThread isMainThread]) {
[cocoagsg->_context update];
_context_needs_update = false;
} else {
cocoagsg->unlock_context();
return false;
}
}
// Lock the view for drawing.
@ -349,6 +354,18 @@ process_events() {
}
[pool release];
if (_context_needs_update && _gsg != nullptr) {
CocoaGraphicsStateGuardian *cocoagsg;
DCAST_INTO_V(cocoagsg, _gsg);
if (cocoagsg != nullptr && cocoagsg->_context != nil) {
cocoagsg->lock_context();
_context_needs_update = false;
[cocoagsg->_context update];
cocoagsg->unlock_context();
}
}
}
/**
@ -1194,6 +1211,18 @@ set_properties_now(WindowProperties &properties) {
break;
}
}
if (_context_needs_update && _gsg != nullptr) {
CocoaGraphicsStateGuardian *cocoagsg;
DCAST_INTO_V(cocoagsg, _gsg);
if (cocoagsg != nullptr && cocoagsg->_context != nil) {
cocoagsg->lock_context();
_context_needs_update = false;
[cocoagsg->_context update];
cocoagsg->unlock_context();
}
}
}
/**