Skip to content

Commit

Permalink
fix: *actually* synchronize parameter editor preview calls (fixes cra…
Browse files Browse the repository at this point in the history
…shes)
  • Loading branch information
hello-adam committed Apr 23, 2021
1 parent ccd01f3 commit a53e554
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/hobbits-widgets/abstractparametereditor.h
Expand Up @@ -3,6 +3,8 @@

#include <QWidget>
#include <QThread>
#include <QSemaphore>
#include <QSemaphoreReleaser>
#include <QtConcurrent/QtConcurrent>
#include "bitcontainerpreview.h"
#include "pluginactionprogress.h"
Expand All @@ -14,6 +16,8 @@ class HOBBITSWIDGETSSHARED_EXPORT AbstractParameterEditor : public QWidget
Q_OBJECT

public:
AbstractParameterEditor() : m_previewSem(2) {}

virtual QString title() = 0;

virtual bool setParameters(QJsonObject parameters) = 0;
Expand All @@ -26,7 +30,11 @@ class HOBBITSWIDGETSSHARED_EXPORT AbstractParameterEditor : public QWidget
void previewBits(QSharedPointer<BitContainerPreview> container,
QSharedPointer<PluginActionProgress> progress)
{
QMutexLocker(&this->m_previewLock);
if (!this->m_previewSem.tryAcquire()) {
return;
}
QSemaphoreReleaser releaser(&this->m_previewSem);
QMutexLocker locker(&this->m_previewLock);
if (QThread::currentThread() == this->thread()) {
// Called from UI thread
previewBitsImpl(container, progress);
Expand Down Expand Up @@ -76,6 +84,7 @@ protected slots:

private:
QMutex m_previewLock;
QSemaphore m_previewSem;
};

#endif // ABSTRACTPARAMETEREDITOR_H

0 comments on commit a53e554

Please sign in to comment.