From e792a67dc60ad1a11c0b1ed9213a6d0aca0fd1df Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 20 Jul 2019 21:03:45 +0200 Subject: [PATCH 1/3] Improve thread safety and remove an unnecessary string allocation from MsgAlert s_msg_handler still seems thread unsafe, not sure if it should be or not --- Source/Core/Common/MsgHandler.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/Core/Common/MsgHandler.cpp b/Source/Core/Common/MsgHandler.cpp index 6b24991526..556caaf78c 100644 --- a/Source/Core/Common/MsgHandler.cpp +++ b/Source/Core/Common/MsgHandler.cpp @@ -83,35 +83,27 @@ std::string GetStringT(const char* string) bool MsgAlert(bool yes_no, MsgType style, const char* format, ...) { // Read message and write it to the log - std::string caption; + const char* caption = ""; char buffer[2048]; - static std::string info_caption; - static std::string warn_caption; - static std::string ques_caption; - static std::string crit_caption; - - if (info_caption.empty()) - { - info_caption = s_str_translator(_trans("Information")); - ques_caption = s_str_translator(_trans("Question")); - warn_caption = s_str_translator(_trans("Warning")); - crit_caption = s_str_translator(_trans("Critical")); - } + static const std::string info_caption = s_str_translator(_trans("Information")); + static const std::string warn_caption = s_str_translator(_trans("Question")); + static const std::string ques_caption = s_str_translator(_trans("Warning")); + static const std::string crit_caption = s_str_translator(_trans("Critical")); switch (style) { case MsgType::Information: - caption = info_caption; + caption = info_caption.c_str(); break; case MsgType::Question: - caption = ques_caption; + caption = ques_caption.c_str(); break; case MsgType::Warning: - caption = warn_caption; + caption = warn_caption.c_str(); break; case MsgType::Critical: - caption = crit_caption; + caption = crit_caption.c_str(); break; } @@ -120,13 +112,13 @@ bool MsgAlert(bool yes_no, MsgType style, const char* format, ...) CharArrayFromFormatV(buffer, sizeof(buffer) - 1, s_str_translator(format).c_str(), args); va_end(args); - ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer); + ERROR_LOG(MASTER_LOG, "%s: %s", caption, buffer); // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored if (s_msg_handler != nullptr && (s_alert_enabled || style == MsgType::Question || style == MsgType::Critical)) { - return s_msg_handler(caption.c_str(), buffer, yes_no, style); + return s_msg_handler(caption, buffer, yes_no, style); } return true; From 7045c68327ab4218149daf63b669242de94e42c5 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 20 Jul 2019 21:04:27 +0200 Subject: [PATCH 2/3] When clicking "Ignore for this session", make message box handler return true, so asserts can actually be skipped with this option --- Source/Core/DolphinQt/Main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index 58db5bb85f..ebbf53dd9e 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -68,7 +68,10 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no return true; if (button == QMessageBox::Ignore) + { Common::SetEnableAlert(false); + return true; + } return false; }); From 518d96ad48c34815f16e64c690c9526709c88e53 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 21 Jul 2019 08:50:35 +0200 Subject: [PATCH 3/3] Remove duplicated "Ignore and countinue?" --- Source/Core/Common/Assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/Assert.h b/Source/Core/Common/Assert.h index 5be700f338..661dba5d8e 100644 --- a/Source/Core/Common/Assert.h +++ b/Source/Core/Common/Assert.h @@ -15,7 +15,7 @@ { \ if (!(_a_)) \ { \ - if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__)) \ + if (!PanicYesNo(_fmt_, __VA_ARGS__)) \ Crash(); \ } \ } while (0)