Fix f6d5c01: Delay deletion when closing windows

This commit is contained in:
glx22
2021-05-15 23:12:25 +02:00
committed by Loïc Guilloux
parent ef991b1772
commit 994bf19aef
35 changed files with 231 additions and 166 deletions

View File

@@ -250,7 +250,7 @@ public:
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
/* If company gets shut down, while displaying an error about it, remove the error message. */
if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this;
if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) this->Close();
}
void SetStringParameters(int widget) const override
@@ -298,20 +298,21 @@ public:
void OnMouseLoop() override
{
/* Disallow closing the window too easily, if timeout is disabled */
if (_right_button_down && !this->display_timer.HasElapsed()) delete this;
if (_right_button_down && !this->display_timer.HasElapsed()) this->Close();
}
void OnRealtimeTick(uint delta_ms) override
{
if (this->display_timer.CountElapsed(delta_ms) == 0) return;
delete this;
this->Close();
}
~ErrmsgWindow()
void Close() override
{
SetRedErrorSquare(INVALID_TILE);
if (_window_system_initialized) ShowFirstError();
this->Window::Close();
}
/**
@@ -354,7 +355,7 @@ void UnshowCriticalError()
if (_window_system_initialized && w != nullptr) {
if (w->IsCritical()) _error_list.push_front(*w);
_window_system_initialized = false;
delete w;
w->Close();
}
}
@@ -403,18 +404,20 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
data.CopyOutDParams();
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
if (w != nullptr && w->IsCritical()) {
/* A critical error is currently shown. */
if (wl == WL_CRITICAL) {
/* Push another critical error in the queue of errors,
* but do not put other errors in the queue. */
_error_list.push_back(data);
if (w != nullptr) {
if (w->IsCritical()) {
/* A critical error is currently shown. */
if (wl == WL_CRITICAL) {
/* Push another critical error in the queue of errors,
* but do not put other errors in the queue. */
_error_list.push_back(data);
}
return;
}
} else {
/* Nothing or a non-critical error was shown. */
delete w;
new ErrmsgWindow(data);
/* A non-critical error was shown. */
w->Close();
}
new ErrmsgWindow(data);
}
@@ -425,7 +428,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
bool HideActiveErrorMessage() {
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
if (w == nullptr) return false;
delete w;
w->Close();
return true;
}