From eaedcfea4c9bfefb4870c08ab83be7072c7433e4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 12 Jun 2020 12:20:20 +0200 Subject: [PATCH] Gui: [skip ci] fix some thread issues: avoid to crash the application when trying to create thumbnail from worker thread avoid that application behaves weirdly when triggering an action update from worker thread --- src/Gui/MainWindow.cpp | 11 ++++++++++- src/Gui/Thumbnail.cpp | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 41a15ca259..9bfdc498f8 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1325,7 +1325,16 @@ void MainWindow::updateActions(bool delay) return; if (!d->activityTimer->isActive()) { - d->activityTimer->start(150); + // If for some reason updateActions() is called from a worker thread + // we must avoid to directly call QTimer::start() because this leaves + // the whole application in a weird state + if (d->activityTimer->thread() != QThread::currentThread()) { + QMetaObject::invokeMethod(d->activityTimer, "start", Qt::QueuedConnection, + QGenericReturnArgument(), Q_ARG(int, 150)); + } + else { + d->activityTimer->start(150); + } } else if (delay) { if (!d->actionUpdateDelay) diff --git a/src/Gui/Thumbnail.cpp b/src/Gui/Thumbnail.cpp index eccf1ef9b2..58109e8bb5 100644 --- a/src/Gui/Thumbnail.cpp +++ b/src/Gui/Thumbnail.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include @@ -88,6 +89,11 @@ void Thumbnail::SaveDocFile (Base::Writer &writer) const return; QImage img; if (this->viewer->isActiveWindow()) { + if (this->viewer->thread() != QThread::currentThread()) { + qWarning("Cannot create a thumbnail from non-GUI thread"); + return; + } + QColor invalid; this->viewer->imageFromFramebuffer(this->size, this->size, 0, invalid, img); }