Skip to content

Commit 079a747

Browse files
Synchronize changes from 1.6 branch [ci skip]
f522314 Revert 68a8db6 to curb unknown camera performance regression in 1.6 (Revised changes are planned for 1.7 only) e17a7a1 Revert "Addendum to 9ff02d5" 737d587 Fix main menu memory leaks 8052d64 Addendum #2 to f2e93f2 6fd9d8b Addendum to f2e93f2 (CSettings leak): Use new cleanup helper d1f8162 Fix mem leaks in CSettings
2 parents a9d4278 + f522314 commit 079a747

File tree

15 files changed

+515
-428
lines changed

15 files changed

+515
-428
lines changed

Client/core/CMainMenu.cpp

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,33 +358,64 @@ CMainMenu::CMainMenu(CGUI* pManager)
358358

359359
CMainMenu::~CMainMenu()
360360
{
361-
// Destroy GUI items
362-
delete m_pBackground;
363-
delete m_pCanvas;
364-
delete m_pFiller;
365-
delete m_pFiller2;
366-
delete m_pLogo;
367-
delete m_pLatestNews;
368-
delete m_pVersion;
369-
delete m_pMenuArea;
370-
371-
// Destroy the menu items. Note: The disconnect item isn't always in the
372-
// list of menu items (it's only in there when we're in game). This means we
373-
// don't delete it when we iterate the list and delete it separately - the
374-
// menu item itself still exists even when it's no in the list of menu
375-
// items. Perhaps there should be a separate list of loaded items really.
376-
for (std::deque<sMenuItem*>::iterator it = m_menuItems.begin(); it != m_menuItems.end(); ++it)
361+
auto destroyElement = [this](auto*& element) {
362+
if (!element)
363+
return;
364+
m_pManager->DestroyElementRecursive(element);
365+
element = nullptr;
366+
};
367+
368+
for (uint i = 0; i < CORE_MTA_NEWS_ITEMS; ++i)
377369
{
378-
if ((*it) != m_pDisconnect)
370+
destroyElement(m_pNewsItemLabels[i]);
371+
destroyElement(m_pNewsItemShadowLabels[i]);
372+
destroyElement(m_pNewsItemDateLabels[i]);
373+
destroyElement(m_pNewsItemNEWLabels[i]);
374+
}
375+
376+
for (sMenuItem* pItem : m_menuItems)
377+
{
378+
if (!pItem || pItem == m_pDisconnect)
379+
continue;
380+
381+
if (pItem->image)
382+
{
383+
m_pManager->DestroyElementRecursive(pItem->image);
384+
pItem->image = nullptr;
385+
}
386+
387+
delete pItem;
388+
}
389+
m_menuItems.clear();
390+
m_unhoveredItems.clear();
391+
m_pHoveredItem = nullptr;
392+
393+
if (m_pDisconnect)
394+
{
395+
if (m_pDisconnect->image)
379396
{
380-
delete (*it)->image;
381-
delete (*it);
397+
m_pManager->DestroyElementRecursive(m_pDisconnect->image);
398+
m_pDisconnect->image = nullptr;
382399
}
400+
401+
delete m_pDisconnect;
402+
m_pDisconnect = nullptr;
383403
}
384404

385-
delete m_pDisconnect->image;
386-
delete m_pDisconnect;
405+
destroyElement(m_pMenuArea);
406+
destroyElement(m_pLogo);
407+
destroyElement(m_pLatestNews);
408+
destroyElement(m_pVersion);
409+
410+
destroyElement(m_pCanvas);
411+
destroyElement(m_pBackground);
412+
destroyElement(m_pFiller);
413+
destroyElement(m_pFiller2);
414+
387415
delete m_pLanguageSelector;
416+
m_pLanguageSelector = nullptr;
417+
delete m_pNewsBrowser;
418+
m_pNewsBrowser = nullptr;
388419
}
389420

390421
void CMainMenu::SetMenuVerticalPosition(int iPosY)

0 commit comments

Comments
 (0)