From 074ab70380c99006dbc36c140703d5d6eb3c781e Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Mon, 24 May 2021 20:01:22 +0100 Subject: [PATCH] Prevent Qt handling Windows Messages while the fatal error message is open --- src/blackmisc/loghandler.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/blackmisc/loghandler.cpp b/src/blackmisc/loghandler.cpp index c7827ac10..6a8e340c1 100644 --- a/src/blackmisc/loghandler.cpp +++ b/src/blackmisc/loghandler.cpp @@ -18,6 +18,7 @@ #include "crashpad/client/simulate_crash.h" #endif +#include #include #include #include @@ -57,7 +58,20 @@ namespace BlackMisc #if defined(Q_CC_MSVC) && defined(QT_NO_DEBUG) if (type == QtFatalMsg) { + struct EventFilter : public QAbstractNativeEventFilter + { + // Prevent Qt from handling Windows Messages while the messagebox is open + virtual bool nativeEventFilter(const QByteArray &, void *message, long *result) override + { + auto msg = static_cast(message); + *result = DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam); + return true; + } + }; + EventFilter ef; + qApp->installNativeEventFilter(&ef); MessageBoxW(nullptr, message.toStdWString().c_str(), nullptr, MB_OK); // display assert dialog in release build + qApp->removeNativeEventFilter(&ef); # if defined(BLACK_USE_CRASHPAD) CRASHPAD_SIMULATE_CRASH(); // workaround inability to catch __fastfail # endif