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));