File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,25 +20,27 @@ DeviceContextPool::DeviceContextPool(ID2D1Device1* d2dDevice)
2020
2121DeviceContextLease DeviceContextPool::TakeLease ()
2222{
23- Lock lock (m_mutex);
24-
25- if (!m_d2dDevice)
26- ThrowHR (RO_E_CLOSED );
27-
28- if (m_deviceContexts.empty ())
23+ ID2D1Device1* localDevice;
2924 {
30- ComPtr<ID2D1DeviceContext1> deviceContext;
31- ThrowIfFailed (m_d2dDevice->CreateDeviceContext (
32- D2D1_DEVICE_CONTEXT_OPTIONS_NONE ,
33- &deviceContext));
34- return DeviceContextLease (this , std::move (deviceContext));
35- }
36- else
37- {
38- DeviceContextLease newLease (this , std::move (m_deviceContexts.back ()));
39- m_deviceContexts.pop_back ();
40- return newLease;
25+ Lock lock (m_mutex);
26+
27+ if (!m_deviceContexts.empty ())
28+ {
29+ DeviceContextLease newLease (this , std::move (m_deviceContexts.back ()));
30+ m_deviceContexts.pop_back ();
31+ return newLease;
32+ }
33+ localDevice = m_d2dDevice;
4134 }
35+ // Release lock before creating the device context to avoid potential deadlock scenarios
36+ if (!localDevice)
37+ ThrowHR (RO_E_CLOSED );
38+
39+ ComPtr<ID2D1DeviceContext1> deviceContext;
40+ ThrowIfFailed (localDevice->CreateDeviceContext (
41+ D2D1_DEVICE_CONTEXT_OPTIONS_NONE ,
42+ &deviceContext));
43+ return DeviceContextLease (this , std::move (deviceContext));
4244}
4345
4446
You can’t perform that action at this time.
0 commit comments