diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index 526e66f4c5ff5..7244fc3b2a72a 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -248,13 +248,22 @@ } if (drawable_) { - TRACE_EVENT0("flutter", "waitUntilScheduled"); id command_buffer = ContextMTL::Cast(context.get()) ->CreateMTLCommandBuffer("Present Waiter Command Buffer"); - [command_buffer commit]; - [command_buffer waitUntilScheduled]; - [drawable_ present]; + // If the threads have been merged, or there is a pending frame capture, + // then block on cmd buffer scheduling to ensure that the + // transaction/capture work correctly. + if ([[NSThread currentThread] isMainThread] || + [[MTLCaptureManager sharedCaptureManager] isCapturing]) { + TRACE_EVENT0("flutter", "waitUntilScheduled"); + [command_buffer commit]; + [command_buffer waitUntilScheduled]; + [drawable_ present]; + } else { + [command_buffer presentDrawable:drawable_]; + [command_buffer commit]; + } } return true;