From efde75877dad26a7f36133969a3acd70339eebee Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 31 Dec 2023 05:08:17 +0100 Subject: [PATCH] Fix the abort button --- src/common/widgets/netstartwindow.cpp | 33 +++++++++++++++++++++++---- src/common/widgets/netstartwindow.h | 3 +++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/common/widgets/netstartwindow.cpp b/src/common/widgets/netstartwindow.cpp index 00c93fc7c6..ee6f76fe12 100644 --- a/src/common/widgets/netstartwindow.cpp +++ b/src/common/widgets/netstartwindow.cpp @@ -1,6 +1,7 @@ #include "netstartwindow.h" #include "version.h" +#include "engineerrors.h" #include #include #include @@ -39,12 +40,23 @@ bool NetStartWindow::RunMessageLoop(bool (*newtimer_callback)(void*), void* newu Instance->timer_callback = newtimer_callback; Instance->userdata = newuserdata; + Instance->CallbackException = {}; DisplayWindow::RunLoop(); Instance->timer_callback = nullptr; Instance->userdata = nullptr; + if (Instance->CallbackException) + std::rethrow_exception(Instance->CallbackException); + + // Even though the comment in FBasicStartupScreen::NetLoop says we should return false, the old code actually throws an exception! + // This effectively also means the function always returns true... + if (!Instance->exitreason) + { + throw CExitEvent(0); + } + return Instance->exitreason; } @@ -75,7 +87,7 @@ NetStartWindow::NetStartWindow(const std::string& message, int maxpos) : Widget( void NetStartWindow::SetProgress(int newpos) { - if (pos != newpos) + if (pos != newpos && maxpos > 1) { pos = newpos; FString message; @@ -110,9 +122,22 @@ void NetStartWindow::OnGeometryChanged() void NetStartWindow::OnCallbackTimerExpired() { - if (timer_callback && timer_callback(userdata)) + if (timer_callback) { - exitreason = true; - DisplayWindow::ExitLoop(); + bool result = false; + try + { + result = timer_callback(userdata); + } + catch (...) + { + CallbackException = std::current_exception(); + } + + if (result) + { + exitreason = true; + DisplayWindow::ExitLoop(); + } } } diff --git a/src/common/widgets/netstartwindow.h b/src/common/widgets/netstartwindow.h index c02927f0e9..8dffa4d709 100644 --- a/src/common/widgets/netstartwindow.h +++ b/src/common/widgets/netstartwindow.h @@ -1,6 +1,7 @@ #pragma once #include +#include class TextLabel; class PushButton; @@ -39,5 +40,7 @@ private: bool exitreason = false; + std::exception_ptr CallbackException; + static NetStartWindow* Instance; };