mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 05:40:44 +00:00
Fix the abort button
This commit is contained in:
parent
16e578a0f8
commit
efde75877d
2 changed files with 32 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "netstartwindow.h"
|
||||
#include "version.h"
|
||||
#include "engineerrors.h"
|
||||
#include <zwidget/core/timer.h>
|
||||
#include <zwidget/widgets/textlabel/textlabel.h>
|
||||
#include <zwidget/widgets/pushbutton/pushbutton.h>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <zwidget/core/widget.h>
|
||||
#include <stdexcept>
|
||||
|
||||
class TextLabel;
|
||||
class PushButton;
|
||||
|
@ -39,5 +40,7 @@ private:
|
|||
|
||||
bool exitreason = false;
|
||||
|
||||
std::exception_ptr CallbackException;
|
||||
|
||||
static NetStartWindow* Instance;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue