Skip to content

Commit bc6e7c0

Browse files
committed
Fix GUI related crashes and regressions/bad code
1 parent b596e87 commit bc6e7c0

23 files changed

+262
-43
lines changed

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,69 @@ CServerBrowser::CServerBrowser()
6161
m_BeforeTempServerBrowserType = ServerBrowserTypes::INTERNET;
6262
m_llLastGeneralHelpTime = 0;
6363

64+
m_pFrame = nullptr;
65+
m_pTopWindow = nullptr;
66+
m_pPanel = nullptr;
67+
m_pLockedIcon = nullptr;
68+
m_pQuickConnectHelpWindow = nullptr;
69+
m_pGeneralHelpWindow = nullptr;
70+
71+
for (unsigned int i = 0; i < SearchTypes::MAX_SEARCH_TYPES; ++i)
72+
{
73+
m_pSearchIcons[i] = nullptr;
74+
m_szSearchTypePath[i] = nullptr;
75+
}
76+
77+
for (unsigned int i = 0; i < SERVER_BROWSER_TYPE_COUNT; ++i)
78+
{
79+
m_pTab[i] = nullptr;
80+
m_pServerList[i] = nullptr;
81+
m_pServerListRevision[i] = 0;
82+
m_pServerPlayerListLabel[i] = nullptr;
83+
m_pServerPlayerList[i] = nullptr;
84+
m_pEditServerSearch[i] = nullptr;
85+
m_pServerSearchIcon[i] = nullptr;
86+
m_pLabelInclude[i] = nullptr;
87+
m_pIncludeEmpty[i] = nullptr;
88+
m_pIncludeFull[i] = nullptr;
89+
m_pIncludeLocked[i] = nullptr;
90+
m_pIncludeOffline[i] = nullptr;
91+
m_pIncludeOtherVersions[i] = nullptr;
92+
m_pButtonConnect[i] = nullptr;
93+
m_pButtonConnectIcon[i] = nullptr;
94+
m_pButtonRefresh[i] = nullptr;
95+
m_pButtonRefreshIcon[i] = nullptr;
96+
m_pButtonInfo[i] = nullptr;
97+
m_pButtonInfoIcon[i] = nullptr;
98+
m_pButtonFavourites[i] = nullptr;
99+
m_pEditAddress[i] = nullptr;
100+
m_pLabelAddressDescription[i] = nullptr;
101+
m_pComboAddressHistory[i] = nullptr;
102+
m_pSearchTypeIcon[i] = nullptr;
103+
m_pAddressFavoriteIcon[i] = nullptr;
104+
m_pRemoveFromRecentIcon[i] = nullptr;
105+
m_pComboSearchType[i] = nullptr;
106+
m_pEditSearch[i] = nullptr;
107+
m_pLabelSearchDescription[i] = nullptr;
108+
m_pLabelPassword[i] = nullptr;
109+
m_pEditPassword[i] = nullptr;
110+
m_pServerListStatus[i] = nullptr;
111+
m_pButtonBack[i] = nullptr;
112+
m_pButtonGeneralHelp[i] = nullptr;
113+
m_iSelectedServer[i] = -1;
114+
m_hVersion[i] = CGUIHandle();
115+
m_hLocked[i] = CGUIHandle();
116+
m_hName[i] = CGUIHandle();
117+
m_hPing[i] = CGUIHandle();
118+
m_hPlayers[i] = CGUIHandle();
119+
m_hHost[i] = CGUIHandle();
120+
m_hGame[i] = CGUIHandle();
121+
m_hMap[i] = CGUIHandle();
122+
m_hPlayerName[i] = CGUIHandle();
123+
m_FlashSearchBox[i].uiCount = 0;
124+
m_FlashSearchBox[i].uiNextTime = 0;
125+
}
126+
64127
// Do some initial math
65128
CVector2D resolution = CCore::GetSingleton().GetGUI()->GetResolution();
66129
bool bCreateFrame = true;
@@ -500,6 +563,10 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)
500563
// Player List Columns
501564
m_hPlayerName[type] = m_pServerPlayerList[type]->AddColumn(_("Player list"), 0.75f);
502565

566+
// Create a companion label now so the destructor can safely clean it up later.
567+
m_pServerPlayerListLabel[type] = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTab[type], ""));
568+
m_pServerPlayerListLabel[type]->SetVisible(false);
569+
503570
// Filters
504571
float fLineHeight = SB_BACK_BUTTON_SIZE_Y / 2;
505572
fX = SB_SMALL_SPACER;

Client/gui/CGUIButton_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUIButton_Impl::CGUIButton_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szCaption)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
2121
char szUnique[CGUI_CHAR_SIZE];

Client/gui/CGUICheckBox_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUICheckBox_Impl::CGUICheckBox_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szCaption, bool bChecked)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
2121
char szUnique[CGUI_CHAR_SIZE];

Client/gui/CGUIComboBox_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUIComboBox_Impl::CGUIComboBox_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szCaption)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
2121
char szUnique[CGUI_CHAR_SIZE];

Client/gui/CGUIEdit_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUIEdit_Impl::CGUIEdit_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szEdit)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
2121
char szUnique[CGUI_CHAR_SIZE];

Client/gui/CGUIElement_Impl.cpp

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

1212
#include "StdInc.h"
13+
#include "CGUI_Impl.h"
1314

1415
// Define no-drawing zones, a.k.a. the inside borders in the FrameWindow of BlueLook in pixels
1516
// If something is drawn inside of these areas, the theme border is drawn on top of it
@@ -24,20 +25,65 @@ CGUIElement_Impl::CGUIElement_Impl()
2425
m_pWindow = NULL;
2526
m_pParent = NULL;
2627
m_pManager = NULL;
28+
m_redrawHandle = CGUI_Impl::kInvalidRedrawHandle;
29+
}
30+
31+
void CGUIElement_Impl::SetManager(CGUI_Impl* pManager)
32+
{
33+
if (m_pManager == pManager)
34+
return;
35+
36+
if (m_pManager && m_redrawHandle != CGUI_Impl::kInvalidRedrawHandle)
37+
{
38+
m_pManager->ReleaseRedrawHandle(m_redrawHandle);
39+
m_redrawHandle = CGUI_Impl::kInvalidRedrawHandle;
40+
}
41+
42+
m_pManager = pManager;
43+
44+
if (m_pManager)
45+
{
46+
m_redrawHandle = m_pManager->RegisterRedrawHandle(this);
47+
}
48+
}
49+
50+
void CGUIElement_Impl::UnregisterFromRedrawQueue()
51+
{
52+
if (m_pManager && m_redrawHandle != CGUI_Impl::kInvalidRedrawHandle)
53+
{
54+
m_pManager->RemoveFromRedrawQueue(this);
55+
}
2756
}
2857

2958
void CGUIElement_Impl::DestroyElement()
3059
{
31-
m_pManager->RemoveFromRedrawQueue(reinterpret_cast<CGUIElement*>((m_pWindow)->getUserData()));
60+
UnregisterFromRedrawQueue();
3261

33-
// Clear pointer back to this
34-
m_pWindow->setUserData(NULL);
62+
if (m_pWindow)
63+
{
64+
// Clear pointer back to this
65+
m_pWindow->setUserData(NULL);
3566

36-
// Destroy the control
37-
m_pManager->GetWindowManager()->destroyWindow(m_pWindow);
67+
if (m_pManager)
68+
{
69+
// Destroy the control
70+
m_pManager->GetWindowManager()->destroyWindow(m_pWindow);
71+
}
72+
m_pWindow = NULL;
73+
}
3874

3975
// Destroy the properties list
4076
EmptyProperties();
77+
78+
if (m_pManager && m_redrawHandle != CGUI_Impl::kInvalidRedrawHandle)
79+
{
80+
m_pManager->ReleaseRedrawHandle(m_redrawHandle);
81+
}
82+
83+
m_redrawHandle = CGUI_Impl::kInvalidRedrawHandle;
84+
m_pParent = NULL;
85+
m_pData = NULL;
86+
m_pManager = NULL;
4187
}
4288

4389
void CGUIElement_Impl::SetVisible(bool bVisible)

Client/gui/CGUIElement_Impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <gui/CGUIElement.h>
1515

1616
#include <list>
17+
#include <cstdint>
1718

1819
namespace CEGUI
1920
{
@@ -27,6 +28,8 @@ class CGUIElement_Impl : public CGUIElement
2728
public:
2829
CGUIElement_Impl();
2930

31+
void SetManager(CGUI_Impl* pManager);
32+
3033
void SetVisible(bool bVisible);
3134
bool IsVisible();
3235

@@ -91,6 +94,9 @@ class CGUIElement_Impl : public CGUIElement
9194
CGUIElement* GetParent();
9295

9396
CEGUI::Window* GetWindow() const { return m_pWindow; }
97+
CGUI_Impl* GetManager() const { return m_pManager; }
98+
std::uint32_t GetRedrawHandle() const { return m_redrawHandle; }
99+
void UnregisterFromRedrawQueue();
94100

95101
void ForceRedraw();
96102

@@ -140,6 +146,8 @@ class CGUIElement_Impl : public CGUIElement
140146

141147
CGUI_Impl* m_pManager;
142148

149+
std::uint32_t m_redrawHandle;
150+
143151
void* m_pData;
144152

145153
std::list<CGUIProperty*> m_Properties;

Client/gui/CGUIGridList_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
CGUIGridList_Impl::CGUIGridList_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, bool bFrame)
2121
{
22-
m_pManager = pGUI;
22+
SetManager(pGUI);
2323

2424
// Initialize
2525
m_hUniqueHandle = 0;

Client/gui/CGUILabel_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUILabel_Impl::CGUILabel_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szText)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
2121
char szUnique[CGUI_CHAR_SIZE];

Client/gui/CGUIMemo_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CGUIMemo_Impl::CGUIMemo_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char* szEdit)
1717
{
18-
m_pManager = pGUI;
18+
SetManager(pGUI);
1919

2020
// Get an unique identifier for CEGUI
2121
char szUnique[CGUI_CHAR_SIZE];

0 commit comments

Comments
 (0)