From 10caef64040b4487db893236bc71a1e334201205 Mon Sep 17 00:00:00 2001 From: benstevens48 Date: Tue, 24 Feb 2026 12:21:10 +0000 Subject: [PATCH] unlock earlier to improve concurrency --- winrt/lib/drawing/DeviceContextPool.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/winrt/lib/drawing/DeviceContextPool.cpp b/winrt/lib/drawing/DeviceContextPool.cpp index 2a331cd2c..c41432724 100644 --- a/winrt/lib/drawing/DeviceContextPool.cpp +++ b/winrt/lib/drawing/DeviceContextPool.cpp @@ -27,8 +27,12 @@ DeviceContextLease DeviceContextPool::TakeLease() if (m_deviceContexts.empty()) { + //Store a local copy of the non-null device pointer before unlocking. + ComPtr localDevice(m_d2dDevice); + //Release lock before creating the device context to avoid potential deadlock scenarios. + lock.unlock(); ComPtr deviceContext; - ThrowIfFailed(m_d2dDevice->CreateDeviceContext( + ThrowIfFailed(localDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &deviceContext)); return DeviceContextLease(this, std::move(deviceContext));