Don't leak global objects in Direct2D code.
Ensure that all globals are freed on library shutdown by using a module just to perform this cleanup. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77753 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
#include "wx/dc.h"
|
#include "wx/dc.h"
|
||||||
#include "wx/dynlib.h"
|
#include "wx/dynlib.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/module.h"
|
||||||
#include "wx/msw/private/comptr.h"
|
#include "wx/msw/private/comptr.h"
|
||||||
#include "wx/private/graphics.h"
|
#include "wx/private/graphics.h"
|
||||||
#include "wx/stack.h"
|
#include "wx/stack.h"
|
||||||
@@ -3444,7 +3445,7 @@ private :
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxD2DRenderer,wxGraphicsRenderer)
|
IMPLEMENT_DYNAMIC_CLASS(wxD2DRenderer,wxGraphicsRenderer)
|
||||||
|
|
||||||
static wxScopedPtr<wxD2DRenderer> gs_D2DRenderer;
|
static wxD2DRenderer *gs_D2DRenderer = NULL;
|
||||||
|
|
||||||
wxGraphicsRenderer* wxGraphicsRenderer::GetDirect2DRenderer()
|
wxGraphicsRenderer* wxGraphicsRenderer::GetDirect2DRenderer()
|
||||||
{
|
{
|
||||||
@@ -3453,10 +3454,10 @@ wxGraphicsRenderer* wxGraphicsRenderer::GetDirect2DRenderer()
|
|||||||
|
|
||||||
if (!gs_D2DRenderer)
|
if (!gs_D2DRenderer)
|
||||||
{
|
{
|
||||||
gs_D2DRenderer.reset(new wxD2DRenderer());
|
gs_D2DRenderer = new wxD2DRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
return gs_D2DRenderer.get();
|
return gs_D2DRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxD2DRenderer::wxD2DRenderer()
|
wxD2DRenderer::wxD2DRenderer()
|
||||||
@@ -3715,4 +3716,48 @@ ID2D1Factory* wxGetD2DFactory(wxGraphicsRenderer* renderer)
|
|||||||
return static_cast<wxD2DRenderer*>(renderer)->GetD2DFactory();
|
return static_cast<wxD2DRenderer*>(renderer)->GetD2DFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Module ensuring all global/singleton objects are destroyed on shutdown.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxDirect2DModule : public wxModule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDirect2DModule()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnInit() wxOVERRIDE
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnExit() wxOVERRIDE
|
||||||
|
{
|
||||||
|
if ( gs_WICImagingFactory )
|
||||||
|
{
|
||||||
|
gs_WICImagingFactory->Release();
|
||||||
|
gs_WICImagingFactory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( gs_IDWriteFactory )
|
||||||
|
{
|
||||||
|
gs_IDWriteFactory->Release();
|
||||||
|
gs_IDWriteFactory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( gs_D2DRenderer )
|
||||||
|
{
|
||||||
|
delete gs_D2DRenderer;
|
||||||
|
gs_D2DRenderer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxDECLARE_DYNAMIC_CLASS(wxDirect2DModule);
|
||||||
|
};
|
||||||
|
|
||||||
|
wxIMPLEMENT_DYNAMIC_CLASS(wxDirect2DModule, wxModule);
|
||||||
|
|
||||||
|
|
||||||
#endif // wxUSE_GRAPHICS_DIRECT2D
|
#endif // wxUSE_GRAPHICS_DIRECT2D
|
||||||
|
Reference in New Issue
Block a user