Skip to content

Commit 6fd9d8b

Browse files
committed
Addendum to f2e93f2 (CSettings leak): Use new cleanup helper
1 parent d1f8162 commit 6fd9d8b

File tree

7 files changed

+61
-249
lines changed

7 files changed

+61
-249
lines changed

Client/core/CSettings.cpp

Lines changed: 18 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include <algorithm>
14+
#include <vector>
15+
#include "../gui/GuiCleanup.h"
16+
#include "../gui/CGUIElement_Impl.h"
1317
#include <core/CClientCommands.h>
1418
#include <game/CGame.h>
1519
#include <game/CSettings.h>
@@ -239,6 +243,8 @@ void CSettings::ResetGuiPointers()
239243
m_pJoypadLabels.clear();
240244
m_pJoypadButtons.clear();
241245

246+
m_pSelectedBind = NULL;
247+
242248
m_pControlsMouseLabel = NULL;
243249
m_pInvertMouse = NULL;
244250
m_pSteerWithMouse = NULL;
@@ -1826,259 +1832,28 @@ void CSettings::DestroyGUI()
18261832
RemoveAllKeyBindSections();
18271833
m_bBrowserListsChanged = false;
18281834
m_bBrowserListsLoadEnabled = false;
1835+
m_pSelectedBind = NULL;
18291836
ResetGuiPointers();
18301837
return;
18311838
}
18321839

1833-
// Buttons, edits, checkboxes, and labels allocated during CreateGUI / CreateInterfaceTabGUI.
1834-
SAFE_DELETE(m_pButtonCancel);
1835-
SAFE_DELETE(m_pButtonOK);
1836-
SAFE_DELETE(m_pLabelNick);
1837-
SAFE_DELETE(m_pButtonGenerateNick);
1838-
SAFE_DELETE(m_pButtonGenerateNickIcon);
1839-
SAFE_DELETE(m_pEditNick);
1840-
SAFE_DELETE(m_pSavePasswords);
1841-
SAFE_DELETE(m_pAutoRefreshBrowser);
1842-
1843-
SAFE_DELETE(m_pVideoGeneralLabel);
1844-
SAFE_DELETE(m_pVideoResolutionLabel);
1845-
SAFE_DELETE(m_pComboResolution);
1846-
SAFE_DELETE(m_pCheckBoxMipMapping);
1847-
SAFE_DELETE(m_pCheckBoxWindowed);
1848-
SAFE_DELETE(m_pCheckBoxDPIAware);
1849-
SAFE_DELETE(m_pCheckBoxHudMatchAspectRatio);
1850-
SAFE_DELETE(m_pCheckBoxMinimize);
1851-
SAFE_DELETE(m_pMapRenderingLabel);
1852-
SAFE_DELETE(m_pComboFxQuality);
1853-
SAFE_DELETE(m_pFXQualityLabel);
1854-
SAFE_DELETE(m_pComboAspectRatio);
1855-
SAFE_DELETE(m_pAspectRatioLabel);
1856-
SAFE_DELETE(m_pCheckBoxVolumetricShadows);
1857-
SAFE_DELETE(m_pCheckBoxDeviceSelectionDialog);
1858-
SAFE_DELETE(m_pCheckBoxShowUnsafeResolutions);
1859-
SAFE_DELETE(m_pCheckBoxAllowScreenUpload);
1860-
SAFE_DELETE(m_pCheckBoxAllowExternalSounds);
1861-
SAFE_DELETE(m_pCheckBoxCustomizedSAFiles);
1862-
SAFE_DELETE(m_pCheckBoxAllowDiscordRPC);
1863-
SAFE_DELETE(m_pCheckBoxAllowSteamClient);
1864-
SAFE_DELETE(m_pCheckBoxAlwaysShowTransferBox);
1865-
SAFE_DELETE(m_pCheckBoxGrass);
1866-
SAFE_DELETE(m_pCheckBoxHeatHaze);
1867-
SAFE_DELETE(m_pCheckBoxTyreSmokeParticles);
1868-
SAFE_DELETE(m_pCheckBoxHighDetailVehicles);
1869-
SAFE_DELETE(m_pCheckBoxHighDetailPeds);
1870-
SAFE_DELETE(m_pCheckBoxBlur);
1871-
SAFE_DELETE(m_pCheckBoxCoronaReflections);
1872-
SAFE_DELETE(m_pCheckBoxDynamicPedShadows);
1873-
SAFE_DELETE(m_pFieldOfViewLabel);
1874-
SAFE_DELETE(m_pFieldOfView);
1875-
SAFE_DELETE(m_pFieldOfViewValueLabel);
1876-
SAFE_DELETE(m_pDrawDistanceLabel);
1877-
SAFE_DELETE(m_pDrawDistance);
1878-
SAFE_DELETE(m_pDrawDistanceValueLabel);
1879-
SAFE_DELETE(m_pBrightnessLabel);
1880-
SAFE_DELETE(m_pBrightness);
1881-
SAFE_DELETE(m_pBrightnessValueLabel);
1882-
SAFE_DELETE(m_pBorderlessGammaToggle);
1883-
SAFE_DELETE(m_pBorderlessGammaLabel);
1884-
SAFE_DELETE(m_pBorderlessGamma);
1885-
SAFE_DELETE(m_pBorderlessGammaValueLabel);
1886-
SAFE_DELETE(m_pBorderlessBrightnessToggle);
1887-
SAFE_DELETE(m_pBorderlessBrightnessLabel);
1888-
SAFE_DELETE(m_pBorderlessBrightness);
1889-
SAFE_DELETE(m_pBorderlessBrightnessValueLabel);
1890-
SAFE_DELETE(m_pBorderlessContrastToggle);
1891-
SAFE_DELETE(m_pBorderlessContrastLabel);
1892-
SAFE_DELETE(m_pBorderlessContrast);
1893-
SAFE_DELETE(m_pBorderlessContrastValueLabel);
1894-
SAFE_DELETE(m_pBorderlessSaturationToggle);
1895-
SAFE_DELETE(m_pBorderlessSaturationLabel);
1896-
SAFE_DELETE(m_pBorderlessSaturation);
1897-
SAFE_DELETE(m_pBorderlessSaturationValueLabel);
1898-
SAFE_DELETE(m_pCheckBoxApplyBorderless);
1899-
SAFE_DELETE(m_pCheckBoxApplyFullscreen);
1900-
SAFE_DELETE(m_pAnisotropicLabel);
1901-
SAFE_DELETE(m_pAnisotropic);
1902-
SAFE_DELETE(m_pAnisotropicValueLabel);
1903-
SAFE_DELETE(m_pComboAntiAliasing);
1904-
SAFE_DELETE(m_pAntiAliasingLabel);
1905-
SAFE_DELETE(m_pMapAlphaLabel);
1906-
SAFE_DELETE(m_pMapAlpha);
1907-
SAFE_DELETE(m_pMapAlphaValueLabel);
1908-
SAFE_DELETE(m_pStreamingMemoryLabel);
1909-
SAFE_DELETE(m_pStreamingMemory);
1910-
SAFE_DELETE(m_pStreamingMemoryMinLabel);
1911-
SAFE_DELETE(m_pStreamingMemoryMaxLabel);
1912-
SAFE_DELETE(m_pStreamingMemoryLabelInfo);
1913-
SAFE_DELETE(m_pVideoDefButton);
1914-
1915-
SAFE_DELETE(m_pAdvancedSettingDescriptionLabel);
1916-
SAFE_DELETE(m_pFullscreenStyleLabel);
1917-
SAFE_DELETE(m_pFullscreenStyleCombo);
1918-
SAFE_DELETE(m_pCheckBoxVSync);
1919-
SAFE_DELETE(m_pPriorityLabel);
1920-
SAFE_DELETE(m_pPriorityCombo);
1921-
SAFE_DELETE(m_pPlayerMapImageLabel);
1922-
SAFE_DELETE(m_pPlayerMapImageCombo);
1923-
SAFE_DELETE(m_pFastClothesLabel);
1924-
SAFE_DELETE(m_pFastClothesCombo);
1925-
SAFE_DELETE(m_pAudioGeneralLabel);
1926-
SAFE_DELETE(m_pUserTrackGeneralLabel);
1927-
SAFE_DELETE(m_pBrowserSpeedLabel);
1928-
SAFE_DELETE(m_pBrowserSpeedCombo);
1929-
SAFE_DELETE(m_pSingleDownloadLabel);
1930-
SAFE_DELETE(m_pSingleDownloadCombo);
1931-
SAFE_DELETE(m_pPacketTagLabel);
1932-
SAFE_DELETE(m_pPacketTagCombo);
1933-
SAFE_DELETE(m_pProgressAnimationLabel);
1934-
SAFE_DELETE(m_pProgressAnimationCombo);
1935-
SAFE_DELETE(m_pDebugSettingLabel);
1936-
SAFE_DELETE(m_pDebugSettingCombo);
1937-
SAFE_DELETE(m_pWin8Label);
1938-
SAFE_DELETE(m_pWin8ColorCheckBox);
1939-
SAFE_DELETE(m_pWin8MouseCheckBox);
1940-
SAFE_DELETE(m_pPhotoSavingCheckbox);
1941-
SAFE_DELETE(m_pCheckBoxAskBeforeDisconnect);
1942-
SAFE_DELETE(m_pProcessAffinityCheckbox);
1943-
SAFE_DELETE(m_pUpdateBuildTypeLabel);
1944-
SAFE_DELETE(m_pUpdateBuildTypeCombo);
1945-
SAFE_DELETE(m_pUpdateAutoInstallLabel);
1946-
SAFE_DELETE(m_pUpdateAutoInstallCombo);
1947-
SAFE_DELETE(m_pButtonUpdate);
1948-
SAFE_DELETE(m_pAdvancedMiscLabel);
1949-
SAFE_DELETE(m_pAdvancedUpdaterLabel);
1950-
SAFE_DELETE(m_pCachePathLabel);
1951-
SAFE_DELETE(m_pCachePathValue);
1952-
SAFE_DELETE(m_pCachePathShowButton);
1953-
1954-
SAFE_DELETE(m_pLabelMasterVolume);
1955-
SAFE_DELETE(m_pLabelRadioVolume);
1956-
SAFE_DELETE(m_pLabelSFXVolume);
1957-
SAFE_DELETE(m_pLabelMTAVolume);
1958-
SAFE_DELETE(m_pLabelVoiceVolume);
1959-
SAFE_DELETE(m_pLabelMasterVolumeValue);
1960-
SAFE_DELETE(m_pLabelRadioVolumeValue);
1961-
SAFE_DELETE(m_pLabelSFXVolumeValue);
1962-
SAFE_DELETE(m_pLabelMTAVolumeValue);
1963-
SAFE_DELETE(m_pLabelVoiceVolumeValue);
1964-
SAFE_DELETE(m_pAudioMasterVolume);
1965-
SAFE_DELETE(m_pAudioRadioVolume);
1966-
SAFE_DELETE(m_pAudioSFXVolume);
1967-
SAFE_DELETE(m_pAudioMTAVolume);
1968-
SAFE_DELETE(m_pAudioVoiceVolume);
1969-
SAFE_DELETE(m_pAudioRadioLabel);
1970-
SAFE_DELETE(m_pCheckBoxAudioEqualizer);
1971-
SAFE_DELETE(m_pCheckBoxAudioAutotune);
1972-
SAFE_DELETE(m_pAudioMuteLabel);
1973-
SAFE_DELETE(m_pCheckBoxMuteMaster);
1974-
SAFE_DELETE(m_pCheckBoxMuteSFX);
1975-
SAFE_DELETE(m_pCheckBoxMuteRadio);
1976-
SAFE_DELETE(m_pCheckBoxMuteMTA);
1977-
SAFE_DELETE(m_pCheckBoxMuteVoice);
1978-
SAFE_DELETE(m_pAudioUsertrackLabel);
1979-
SAFE_DELETE(m_pCheckBoxUserAutoscan);
1980-
SAFE_DELETE(m_pLabelUserTrackMode);
1981-
SAFE_DELETE(m_pComboUsertrackMode);
1982-
SAFE_DELETE(m_pAudioDefButton);
1983-
1984-
SAFE_DELETE(m_pBindsList);
1985-
SAFE_DELETE(m_pBindsDefButton);
1986-
1987-
for (CGUILabel* pLabel : m_pJoypadLabels)
1988-
SAFE_DELETE(pLabel);
1989-
m_pJoypadLabels.clear();
1990-
for (CGUIButton* pButton : m_pJoypadButtons)
1991-
SAFE_DELETE(pButton);
1992-
m_pJoypadButtons.clear();
1993-
1994-
SAFE_DELETE(m_pJoypadName);
1995-
SAFE_DELETE(m_pJoypadUnderline);
1996-
SAFE_DELETE(m_pEditDeadzone);
1997-
SAFE_DELETE(m_pEditSaturation);
1998-
1999-
SAFE_DELETE(m_pControlsMouseLabel);
2000-
SAFE_DELETE(m_pInvertMouse);
2001-
SAFE_DELETE(m_pSteerWithMouse);
2002-
SAFE_DELETE(m_pFlyWithMouse);
2003-
SAFE_DELETE(m_pLabelMouseSensitivity);
2004-
SAFE_DELETE(m_pMouseSensitivity);
2005-
SAFE_DELETE(m_pLabelMouseSensitivityValue);
2006-
SAFE_DELETE(m_pLabelVerticalAimSensitivity);
2007-
SAFE_DELETE(m_pVerticalAimSensitivity);
2008-
SAFE_DELETE(m_pLabelVerticalAimSensitivityValue);
2009-
2010-
SAFE_DELETE(m_pControlsJoypadLabel);
2011-
SAFE_DELETE(m_pControlsInputTypePane);
2012-
SAFE_DELETE(m_pStandardControls);
2013-
SAFE_DELETE(m_pClassicControls);
2014-
2015-
SAFE_DELETE(m_pInterfaceLanguageSelector);
2016-
SAFE_DELETE(m_pInterfaceSkinSelector);
2017-
SAFE_DELETE(m_pInterfaceLoadSkin);
2018-
2019-
SAFE_DELETE(m_pChatPresets);
2020-
SAFE_DELETE(m_pChatLoadPreset);
2021-
2022-
for (int i = 0; i < Chat::ColorType::MAX; ++i)
1840+
CEGUI::Window* pRootWindow = nullptr;
1841+
if (CGUIElement_Impl* pWindowImpl = dynamic_cast<CGUIElement_Impl*>(m_pWindow))
1842+
pRootWindow = pWindowImpl->GetWindow();
1843+
if (pRootWindow)
20231844
{
2024-
SAFE_DELETE(m_pChatRed[i]);
2025-
SAFE_DELETE(m_pChatGreen[i]);
2026-
SAFE_DELETE(m_pChatBlue[i]);
2027-
SAFE_DELETE(m_pChatAlpha[i]);
2028-
SAFE_DELETE(m_pChatRedValue[i]);
2029-
SAFE_DELETE(m_pChatGreenValue[i]);
2030-
SAFE_DELETE(m_pChatBlueValue[i]);
2031-
SAFE_DELETE(m_pChatAlphaValue[i]);
2032-
SAFE_DELETE(m_pChatColorPreview[i]);
1845+
// Bottom-up pass that mirrors the CEGUI tree ownership.
1846+
DestroyGuiWindowRecursive(pRootWindow);
1847+
}
1848+
else
1849+
{
1850+
SAFE_DELETE(m_pWindow);
20331851
}
2034-
2035-
SAFE_DELETE(m_pPaneChatFont);
2036-
for (int i = 0; i < Chat::Font::MAX; ++i)
2037-
SAFE_DELETE(m_pRadioChatFont[i]);
2038-
2039-
SAFE_DELETE(m_pChatHorizontalCombo);
2040-
SAFE_DELETE(m_pChatVerticalCombo);
2041-
SAFE_DELETE(m_pChatTextAlignCombo);
2042-
SAFE_DELETE(m_pChatOffsetX);
2043-
SAFE_DELETE(m_pChatOffsetY);
2044-
SAFE_DELETE(m_pChatLines);
2045-
SAFE_DELETE(m_pChatScaleX);
2046-
SAFE_DELETE(m_pChatScaleY);
2047-
SAFE_DELETE(m_pChatWidth);
2048-
SAFE_DELETE(m_pChatCssBackground);
2049-
SAFE_DELETE(m_pChatNickCompletion);
2050-
SAFE_DELETE(m_pChatCssText);
2051-
SAFE_DELETE(m_pChatTextBlackOutline);
2052-
SAFE_DELETE(m_pChatLineLife);
2053-
SAFE_DELETE(m_pChatLineFadeout);
2054-
SAFE_DELETE(m_pFlashWindow);
2055-
SAFE_DELETE(m_pTrayBalloon);
2056-
2057-
SAFE_DELETE(m_pLabelBrowserGeneral);
2058-
SAFE_DELETE(m_pCheckBoxRemoteBrowser);
2059-
SAFE_DELETE(m_pCheckBoxRemoteJavascript);
2060-
SAFE_DELETE(m_pLabelBrowserCustomBlacklist);
2061-
SAFE_DELETE(m_pEditBrowserBlacklistAdd);
2062-
SAFE_DELETE(m_pLabelBrowserBlacklistAdd);
2063-
SAFE_DELETE(m_pButtonBrowserBlacklistAdd);
2064-
SAFE_DELETE(m_pGridBrowserBlacklist);
2065-
SAFE_DELETE(m_pButtonBrowserBlacklistRemove);
2066-
SAFE_DELETE(m_pLabelBrowserCustomWhitelist);
2067-
SAFE_DELETE(m_pEditBrowserWhitelistAdd);
2068-
SAFE_DELETE(m_pLabelBrowserWhitelistAdd);
2069-
SAFE_DELETE(m_pButtonBrowserWhitelistAdd);
2070-
SAFE_DELETE(m_pGridBrowserWhitelist);
2071-
SAFE_DELETE(m_pButtonBrowserWhitelistRemove);
2072-
SAFE_DELETE(m_pCheckBoxBrowserGPUEnabled);
2073-
2074-
SAFE_DELETE(m_pTabs);
20751852

20761853
RemoveAllKeyBindSections();
20771854
m_bBrowserListsChanged = false;
20781855
m_bBrowserListsLoadEnabled = false;
2079-
2080-
SAFE_DELETE(m_pWindow);
2081-
m_pWindow = NULL;
1856+
m_pSelectedBind = NULL;
20821857

20831858
ResetGuiPointers();
20841859
}

Client/core/premake5.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project "Client Core"
1414
"../../Shared/sdk",
1515
".",
1616
"../sdk",
17+
"../../vendor/cegui-0.4.0-custom/include",
1718
"../../vendor/tinygettext",
1819
"../../vendor/zlib",
1920
"../../vendor/jpeg-9f",

Client/gui/CGUIElement_Impl.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,6 @@ CGUIElement* CGUIElement_Impl::GetParent()
326326
return m_pParent;
327327
}
328328

329-
CEGUI::Window* CGUIElement_Impl::GetWindow()
330-
{
331-
return m_pWindow;
332-
}
333-
334329
void CGUIElement_Impl::CorrectEdges()
335330
{
336331
CEGUI::Point currentPoint = m_pWindow->getPosition(CEGUI::Absolute);

Client/gui/CGUIElement_Impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CGUIElement_Impl : public CGUIElement
9090
void SetParent(CGUIElement* pParent);
9191
CGUIElement* GetParent();
9292

93-
CEGUI::Window* GetWindow();
93+
CEGUI::Window* GetWindow() const { return m_pWindow; }
9494

9595
void ForceRedraw();
9696

Client/gui/CGUI_Impl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include "GuiCleanup.h"
1314
#include "CEGUIExceptions.h"
1415

1516
using std::list;
1617

18+
void CGUI_Impl::DestroyWindowRecursive(CEGUI::Window* pWindow)
19+
{
20+
DestroyGuiWindowRecursive(pWindow);
21+
}
22+
1723
#define CGUI_MTA_DEFAULT_FONT "tahoma.ttf" // %WINDIR%/font/<...>
1824
#define CGUI_MTA_DEFAULT_FONT_BOLD "tahomabd.ttf" // %WINDIR%/font/<...>
1925
#define CGUI_MTA_CLEAR_FONT "verdana.ttf" // %WINDIR%/font/<...>

Client/gui/CGUI_Impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class CGUI_Impl : public CGUI, public CGUITabList
8383
static CEGUI::String GetUTFString(const char* szInput);
8484
static CEGUI::String GetUTFString(const std::string& strInput);
8585
static CEGUI::String GetUTFString(const CEGUI::String& strInput); // Not defined
86+
static void DestroyWindowRecursive(CEGUI::Window* pWindow);
8687

8788
//
8889
CGUIMessageBox* CreateMessageBox(const char* szTitle, const char* szMessage, unsigned int uiFlags);

Client/gui/GuiCleanup.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: gui/GuiCleanup.h
6+
* PURPOSE: Shared helpers for recursive CEGUI teardown
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
#pragma once
12+
13+
#include <CEGUI.h>
14+
#include <gui/CGUIElement.h>
15+
16+
inline void DestroyGuiWindowRecursive(CEGUI::Window* pWindow)
17+
{
18+
if (!pWindow)
19+
return;
20+
21+
const size_t childCount = pWindow->getChildCount();
22+
for (size_t idx = childCount; idx > 0; --idx)
23+
{
24+
if (CEGUI::Window* pChildWindow = pWindow->getChildAtIdx(static_cast<unsigned int>(idx - 1)))
25+
DestroyGuiWindowRecursive(pChildWindow);
26+
}
27+
28+
if (void* pUserData = pWindow->getUserData())
29+
{
30+
CGUIElement* pElement = reinterpret_cast<CGUIElement*>(pUserData);
31+
pWindow->setUserData(nullptr);
32+
delete pElement;
33+
}
34+
}

0 commit comments

Comments
 (0)