summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorglx22 <glx@openttd.org>2021-05-15 23:12:25 +0200
committerLoïc Guilloux <glx22@users.noreply.github.com>2021-05-29 21:08:25 +0200
commit994bf19aef3dde6c9482434bdc51688f76a937ea (patch)
tree9b45b82d460cb00733144ba0dd64ebc6fde478c2 /src/network
parentef991b1772f5f8b4874f76ea715a9a95811ad979 (diff)
downloadopenttd-994bf19aef3dde6c9482434bdc51688f76a937ea.tar.xz
Fix f6d5c01: Delay deletion when closing windows
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_chat_gui.cpp7
-rw-r--r--src/network/network_content_gui.cpp18
-rw-r--r--src/network/network_content_gui.h6
-rw-r--r--src/network/network_gui.cpp2
4 files changed, 16 insertions, 17 deletions
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 068a5314e..53546aa87 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -307,9 +307,10 @@ struct NetworkChatWindow : public Window {
PositionNetworkChatWindow(this);
}
- ~NetworkChatWindow()
+ void Close() override
{
InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
+ this->Window::Close();
}
void FindWindowPlacementAndResize(int def_width, int def_height) override
@@ -470,7 +471,7 @@ struct NetworkChatWindow : public Window {
FALLTHROUGH;
case WID_NC_CLOSE: /* Cancel */
- delete this;
+ this->Close();
break;
}
}
@@ -497,7 +498,7 @@ struct NetworkChatWindow : public Window {
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
- if (data == this->dest) delete this;
+ if (data == this->dest) this->Close();
}
};
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index dd9590e99..8c75cb572 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -109,9 +109,10 @@ BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(W
this->InitNested(WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
}
-BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow()
+void BaseNetworkContentDownloadStatusWindow::Close()
{
_network_content_client.RemoveCallback(this);
+ this->Window::Close();
}
void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
@@ -171,8 +172,7 @@ public:
this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
}
- /** Free whatever we've allocated */
- ~NetworkContentDownloadStatusWindow()
+ void Close() override
{
TarScanner::Mode mode = TarScanner::NONE;
for (auto ctype : this->receivedTypes) {
@@ -254,6 +254,8 @@ public:
/* Always invalidate the download window; tell it we are going to be gone */
InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST, 2);
+
+ this->BaseNetworkContentDownloadStatusWindow::Close();
}
void OnClick(Point pt, int widget, int click_count) override
@@ -261,7 +263,7 @@ public:
if (widget == WID_NCDS_CANCELOK) {
if (this->downloaded_bytes != this->total_bytes) {
_network_content_client.CloseConnection();
- delete this;
+ this->Close();
} else {
/* If downloading succeeded, close the online content window. This will close
* the current window as well. */
@@ -549,10 +551,10 @@ public:
this->InvalidateData();
}
- /** Free everything we allocated */
- ~NetworkContentListWindow()
+ void Close() override
{
_network_content_client.RemoveCallback(this);
+ this->Window::Close();
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
@@ -837,7 +839,7 @@ public:
break;
case WID_NCL_CANCEL:
- delete this;
+ this->Close();
break;
case WID_NCL_OPEN_URL:
@@ -941,7 +943,7 @@ public:
{
if (!success) {
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
- delete this;
+ this->Close();
return;
}
diff --git a/src/network/network_content_gui.h b/src/network/network_content_gui.h
index 4853101bb..dd9d9cfdf 100644
--- a/src/network/network_content_gui.h
+++ b/src/network/network_content_gui.h
@@ -32,11 +32,7 @@ public:
*/
BaseNetworkContentDownloadStatusWindow(WindowDesc *desc);
- /**
- * Free everything associated with this window.
- */
- ~BaseNetworkContentDownloadStatusWindow();
-
+ void Close() override;
void DrawWidget(const Rect &r, int widget) const override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override;
};
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 322e128cf..7f179a05f 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -2597,7 +2597,7 @@ struct NetworkCompanyPasswordWindow : public Window {
FALLTHROUGH;
case WID_NCP_CANCEL:
- delete this;
+ this->Close();
break;
case WID_NCP_SAVE_AS_DEFAULT_PASSWORD: