Skip to content
Permalink
Browse files
Merge pull request #10066 from leoetlino/abort-on-panic-alert-option
Add an option to abort when a panic alert occurs
  • Loading branch information
leoetlino committed Aug 30, 2021
2 parents 16a9038 + e091c2e commit d7109b1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
@@ -4,6 +4,7 @@
#include "Common/MsgHandler.h"

#include <cstdarg>
#include <cstdlib>
#include <string>

#ifdef _WIN32
@@ -51,6 +52,7 @@ std::string DefaultStringTranslator(const char* text)
MsgAlertHandler s_msg_handler = DefaultMsgHandler;
StringTranslator s_str_translator = DefaultStringTranslator;
bool s_alert_enabled = true;
bool s_abort_on_panic_alert = false;

const char* GetCaption(MsgType style)
{
@@ -94,6 +96,11 @@ void SetEnableAlert(bool enable)
s_alert_enabled = enable;
}

void SetAbortOnPanicAlert(bool should_abort)
{
s_abort_on_panic_alert = should_abort;
}

std::string GetStringT(const char* string)
{
return s_str_translator(string);
@@ -114,6 +121,12 @@ bool MsgAlert(bool yes_no, MsgType style, const char* format, ...)

ERROR_LOG_FMT(MASTER_LOG, "{}: {}", caption, buffer);

// Panic alerts.
if (style == MsgType::Warning && s_abort_on_panic_alert)
{
std::abort();
}

// Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
if (s_msg_handler != nullptr &&
(s_alert_enabled || style == MsgType::Question || style == MsgType::Critical))
@@ -49,6 +49,7 @@ bool MsgAlertFmt(bool yes_no, MsgType style, const S& format, const Args&... arg
}

void SetEnableAlert(bool enable);
void SetAbortOnPanicAlert(bool should_abort);

// Like fmt::format, except the string becomes translatable
template <typename... Args>
@@ -177,6 +177,7 @@ const Info<int> MAIN_NETWORK_TIMEOUT{{System::Main, "Network", "NetworkTimeout"}
const Info<bool> MAIN_USE_HIGH_CONTRAST_TOOLTIPS{
{System::Main, "Interface", "UseHighContrastTooltips"}, true};
const Info<bool> MAIN_USE_PANIC_HANDLERS{{System::Main, "Interface", "UsePanicHandlers"}, true};
const Info<bool> MAIN_ABORT_ON_PANIC_ALERT{{System::Main, "Interface", "AbortOnPanicAlert"}, false};
const Info<bool> MAIN_OSD_MESSAGES{{System::Main, "Interface", "OnScreenDisplayMessages"}, true};
const Info<bool> MAIN_SKIP_NKIT_WARNING{{System::Main, "Interface", "SkipNKitWarning"}, false};

@@ -142,6 +142,7 @@ extern const Info<int> MAIN_NETWORK_TIMEOUT;

extern const Info<bool> MAIN_USE_HIGH_CONTRAST_TOOLTIPS;
extern const Info<bool> MAIN_USE_PANIC_HANDLERS;
extern const Info<bool> MAIN_ABORT_ON_PANIC_ALERT;
extern const Info<bool> MAIN_OSD_MESSAGES;
extern const Info<bool> MAIN_SKIP_NKIT_WARNING;

@@ -68,10 +68,8 @@ bool IsSettingSaveable(const Config::Location& config_location)
// Main.Interface

&Config::MAIN_USE_PANIC_HANDLERS.GetLocation(),
&Config::MAIN_ABORT_ON_PANIC_ALERT.GetLocation(),
&Config::MAIN_OSD_MESSAGES.GetLocation(),

// Main.Interface

&Config::MAIN_SKIP_NKIT_WARNING.GetLocation(),

// UI.General
@@ -102,6 +102,7 @@ void Init()
VideoBackendBase::ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));

Common::SetEnableAlert(Config::Get(Config::MAIN_USE_PANIC_HANDLERS));
Common::SetAbortOnPanicAlert(Config::Get(Config::MAIN_ABORT_ON_PANIC_ALERT));
}

void Shutdown()

0 comments on commit d7109b1

Please sign in to comment.