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
This commit is contained in:
wmayer
2020-06-12 12:20:20 +02:00
parent f98ed46ad6
commit 02a15cdbe0
2 changed files with 16 additions and 1 deletions

View File

@@ -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)

View File

@@ -29,6 +29,7 @@
# include <QByteArray>
# include <QDateTime>
# include <QImage>
# include <QThread>
#endif
#include <QtOpenGL.h>
@@ -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);
}