From 893f3a6c00028df54289b62ca3b7413a5389a865 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 19 Apr 2020 17:04:36 +0200 Subject: [PATCH] Add wxDirect2DModule dependency on wxOleInitModule This avoids the need for calling CoInitializeEx() and CoUninitialize() in this module itself, it's enough to ensure that wxOleInitModule does it before, or after, before this one is initialized, or uninitialized, respectively. This replaces the earlier fix of 450019dc21 (Ensure COM is still active when Direct2D renderer is in use, 2015-12-30). See #17308. --- src/msw/graphicsd2d.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 7ad74fc4e2..9231d36d6c 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -5247,14 +5247,14 @@ class wxDirect2DModule : public wxModule public: wxDirect2DModule() { + // Using Direct2D requires OLE and, importantly, we must ensure our + // OnExit() runs before it is uninitialized. + AddDependency("wxOleInitModule"); } virtual bool OnInit() wxOVERRIDE { - HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - // RPC_E_CHANGED_MODE is not considered as an error - // - see remarks for wxOleInitialize(). - return SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE; + return true; } virtual void OnExit() wxOVERRIDE @@ -5289,8 +5289,6 @@ public: gs_ID2D1Factory->Release(); gs_ID2D1Factory = NULL; } - - ::CoUninitialize(); } private: