From 637485646dd7431af2b8ac92e553058896429718 Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Mon, 15 Jul 2024 16:23:07 +0000 Subject: [PATCH] FIX(client): Fix crash on mono pos. audio warning from audio thread Merge request #5247 introduced a warning that is triggered when Mumble is configured to use positional audio and only a single channel output is configured. However, this warning is emitted from the audio thread and therefore causes a crash. This is because Qt does not want to add child QObjects from any other thread than main. This commit makes sure the static version of ``logOrDefer`` is called and also adds a check to ``Log::log`` to forward the call to the main thread, if necessary. Fixes #6507 --- src/mumble/AudioOutput.cpp | 2 +- src/mumble/Log.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mumble/AudioOutput.cpp b/src/mumble/AudioOutput.cpp index f67514a61..6bb8f63dc 100644 --- a/src/mumble/AudioOutput.cpp +++ b/src/mumble/AudioOutput.cpp @@ -415,7 +415,7 @@ void AudioOutput::initializeMixer(const unsigned int *chanmasks, bool forceheadp qWarning("AudioOutput: Initialized %d channel %d hz mixer", iChannels, iMixerFreq); if (Global::get().s.bPositionalAudio && iChannels == 1) { - Global::get().l->logOrDefer(Log::Warning, tr("Positional audio cannot work with mono output devices!")); + Log::logOrDefer(Log::Warning, tr("Positional audio cannot work with mono output devices!")); } } diff --git a/src/mumble/Log.cpp b/src/mumble/Log.cpp index 1b1a39a9c..ce7216503 100644 --- a/src/mumble/Log.cpp +++ b/src/mumble/Log.cpp @@ -707,6 +707,15 @@ QString Log::validHtml(const QString &html, QTextCursor *tc) { void Log::log(MsgType mt, const QString &console, const QString &terse, bool ownMessage, const QString &overrideTTS, bool ignoreTTS) { + if (QThread::currentThread() != thread()) { + // Invoke in main thread in order to keep the Qt gods on our side by not calling any UI + // functions from a separate thread (can lead to program crashes) + QMetaObject::invokeMethod(this, "log", Qt::QueuedConnection, Q_ARG(Log::MsgType, mt), + Q_ARG(const QString &, console), Q_ARG(const QString &, terse), + Q_ARG(bool, ownMessage), Q_ARG(const QString &, overrideTTS), Q_ARG(bool, ignoreTTS)); + return; + } + QDateTime dt = QDateTime::currentDateTime(); int ignore = qmIgnore.value(mt);