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:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user