Qt: Backport noreturn ReportFatalError()

This commit is contained in:
Stenzek
2025-12-20 23:49:50 +10:00
parent f4ff36b565
commit bfb9ba1c6d
2 changed files with 3 additions and 7 deletions

View File

@@ -32,7 +32,7 @@ std::optional<std::time_t> GetResourceFileTimestamp(std::string_view filename, b
/// Reports a fatal error on the main thread. This does not assume that the main window exists,
/// unlike ReportErrorAsync(), and will exit the application after the popup is closed.
void ReportFatalError(std::string_view title, std::string_view message);
[[noreturn]] void ReportFatalError(std::string_view title, std::string_view message);
/// Displays an asynchronous error on the UI thread, i.e. doesn't block the caller.
void ReportErrorAsync(std::string_view title, std::string_view message);

View File

@@ -2069,11 +2069,7 @@ void Host::ReportFatalError(std::string_view title, std::string_view message)
{
auto cb = [title = QtUtils::StringViewToQString(title), message = QtUtils::StringViewToQString(message)]() {
QMessageBox::critical(g_main_window && g_main_window->isVisible() ? g_main_window : nullptr, title, message);
#ifndef __APPLE__
std::quick_exit(EXIT_FAILURE);
#else
_exit(EXIT_FAILURE);
#endif
std::abort();
};
// https://stackoverflow.com/questions/34135624/how-to-properly-execute-gui-operations-in-qt-main-thread
@@ -2089,7 +2085,7 @@ void Host::ReportFatalError(std::string_view title, std::string_view message)
timer->moveToThread(ui_thread);
timer->setSingleShot(true);
QObject::connect(timer, &QTimer::timeout, std::move(cb));
QMetaObject::invokeMethod(timer, static_cast<void (QTimer::*)(int)>(&QTimer::start), Qt::QueuedConnection,
QMetaObject::invokeMethod(timer, static_cast<void (QTimer::*)(int)>(&QTimer::start), Qt::BlockingQueuedConnection,
static_cast<int>(0));
}
}