Skip to content

Commit 1d40825

Browse files
committed
Fix major memory leaks in CGUI impl
1 parent 095a124 commit 1d40825

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

Client/gui/CGUI_Impl.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,33 @@ using std::list;
3030
#define CGUI_SA_GOTHIC_SIZE 47
3131
#define CGUI_MTA_SANS_FONT_SIZE 9
3232

33-
CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) : m_HasSchemeLoaded(false), m_fCurrentServerCursorAlpha(1.0f)
33+
CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) :
34+
m_HasSchemeLoaded(false),
35+
m_fCurrentServerCursorAlpha(1.0f),
36+
m_pDevice(pDevice),
37+
m_pRenderer(nullptr),
38+
m_pSystem(nullptr),
39+
m_pFontManager(nullptr),
40+
m_pImageSetManager(nullptr),
41+
m_pSchemeManager(nullptr),
42+
m_pWindowManager(nullptr),
43+
m_pTop(nullptr),
44+
m_pCursor(nullptr),
45+
m_pDefaultFont(nullptr),
46+
m_pSmallFont(nullptr),
47+
m_pBoldFont(nullptr),
48+
m_pClearFont(nullptr),
49+
m_pSAHeaderFont(nullptr),
50+
m_pSAGothicFont(nullptr),
51+
m_pSansFont(nullptr),
52+
m_pUniFont(nullptr),
53+
m_ulPreviousUnique(0),
54+
m_eInputMode(INPUTMODE_NO_BINDS_ON_EDIT),
55+
m_Channel(INPUT_CORE)
3456
{
3557
m_RenderOkTimer.SetMaxIncrement(100);
3658

37-
// Init
38-
m_pDevice = pDevice;
39-
/*
40-
m_pCharacterKeyHandler = NULL;
41-
m_pKeyDownHandler = NULL;
42-
m_pMouseClickHandler = NULL;
43-
m_pMouseDoubleClickHandler = NULL;
44-
m_pMouseWheelHandler = NULL;
45-
m_pMouseMoveHandler = NULL;
46-
m_pMouseEnterHandler = NULL;
47-
m_pMouseLeaveHandler = NULL;
48-
m_pMovedHandler = NULL;
49-
m_pSizedHandler = NULL;
50-
*/
51-
m_Channel = INPUT_CORE;
59+
// Callback arrays are default-initialized to empty state by their constructors
5260

5361
// Create a GUI system and get the windowmanager
5462
m_pRenderer = new CEGUI::DirectX9Renderer(pDevice, 0);
@@ -104,7 +112,19 @@ CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice) : m_HasSchemeLoaded(false), m_fC
104112

105113
CGUI_Impl::~CGUI_Impl()
106114
{
115+
// Clean up font objects to prevent memory leaks
116+
delete m_pUniFont;
117+
delete m_pDefaultFont;
118+
delete m_pSmallFont;
119+
delete m_pBoldFont;
120+
delete m_pClearFont;
121+
delete m_pSAHeaderFont;
122+
delete m_pSAGothicFont;
123+
delete m_pSansFont;
124+
125+
// Clean up CEGUI system - this automatically deletes the renderer
107126
delete CEGUI::System::getSingletonPtr();
127+
// DO NOT delete m_pRenderer - it's already deleted by System destructor
108128
}
109129

110130
void CGUI_Impl::SetSkin(const char* szName)

0 commit comments

Comments
 (0)