diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 90699ef26d..ea48bb8c79 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -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(); + } + } } /**