From 447959b214e823b182ab4bfdbb7334b0816be506 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 15 Dec 2025 16:42:36 +0000 Subject: [PATCH] Fix #14916: Duration of error message window could be too short. (#14919) The timer for automatically closing the error message was started when creating the window, instead of when first displaying the window. --- src/error_gui.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/error_gui.cpp b/src/error_gui.cpp index 6efbf1ff55..cf396be830 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -101,22 +101,17 @@ private: uint height_summary = 0; ///< Height of the #summary_msg string in pixels in the #WID_EM_MESSAGE widget. uint height_detailed = 0; ///< Height of the #detailed_msg string in pixels in the #WID_EM_MESSAGE widget. uint height_extra = 0; ///< Height of the #extra_msg string in pixels in the #WID_EM_MESSAGE widget. - TimeoutTimer display_timeout; + + TimeoutTimer display_timeout = {std::chrono::seconds(_settings_client.gui.errmsg_duration), [this]() { + this->Close(); + }}; public: ErrmsgWindow(const ErrorMessageData &data) : Window(data.HasFace() ? _errmsg_face_desc : _errmsg_desc), - ErrorMessageData(data), - display_timeout(std::chrono::seconds(_settings_client.gui.errmsg_duration), [this]() { - this->Close(); - }) + ErrorMessageData(data) { this->InitNested(); - - /* Only start the timeout if the message is not critical. */ - if (!this->is_critical) { - this->display_timeout.Reset(); - } } void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override @@ -222,6 +217,17 @@ public: } } + void OnPaint() override + { + /* Start the timeout if not already started and the message is not critical. This is handled during OnPaint so that any delay between + * creating the window and displaying it does not affect how long the message is visible. */ + if (!this->is_critical && this->display_timeout.HasFired()) { + this->display_timeout.Reset(); + } + + this->Window::OnPaint(); + } + void OnMouseLoop() override { /* Disallow closing the window too easily, if timeout is disabled */