diff --git a/intern/ghost/intern/GHOST_ContextMTL.mm b/intern/ghost/intern/GHOST_ContextMTL.mm index 66da5873514..cb34a8ebc45 100644 --- a/intern/ghost/intern/GHOST_ContextMTL.mm +++ b/intern/ghost/intern/GHOST_ContextMTL.mm @@ -21,6 +21,7 @@ #import #include +#include #include static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT_EDR = MTLPixelFormatRGBA16Float; @@ -121,6 +122,10 @@ GHOST_ContextMTL::GHOST_ContextMTL(const GHOST_ContextParams &context_params, GHOST_ContextMTL::~GHOST_ContextMTL() { + /* Multiple threads can release their own context at the same time. */ + static std::mutex mutex; + std::scoped_lock lock(mutex); + metalFree(); if (owns_metal_device_) {