renderer: implemented function to wait for workers in the main thread

The workers run in separate threads meaning if any significant change is made
(e.g. parameters changing, or even closing the program), these workers may still
be mid-render. This is particularly problematic when closing since the nodes a
worker is rendering may be deleted mid-render. Render backends now have a
function that pauses the main thread (but starts a second event loop so the UI
isn't frozen) until the worker threads are all finished. This way, massive
changes can be made safely without race conditions.
This commit is contained in:
itsmattkc
2020-01-22 17:11:17 +11:00
parent fdbaa75dff
commit 24f7eeb210
11 changed files with 197 additions and 20 deletions
+1
View File
@@ -22,6 +22,7 @@ add_subdirectory(keyframeproperties)
add_subdirectory(loadsave)
add_subdirectory(preferences)
add_subdirectory(projectproperties)
add_subdirectory(rendercancel)
add_subdirectory(sequence)
add_subdirectory(speedduration)
@@ -105,12 +105,15 @@ void PreferencesAudioTab::Accept()
// FIXME: Qt documentation states that QAudioDeviceInfo::deviceName() is a "unique identifiers", which would make them
// ideal for saving in preferences, but in practice they don't actually appear to be unique.
// See: https://bugreports.qt.io/browse/QTBUG-16841
Config::Current()["AudioOutput"] = selected_output_name;
Config::Current()["AudioInput"] = selected_input_name;
if (Config::Current()["AudioOutput"] != selected_output_name) {
Config::Current()["AudioOutput"] = selected_output_name;
AudioManager::instance()->SetOutputDevice(selected_output);
}
// Finally, set these as the current device
AudioManager::instance()->SetOutputDevice(selected_output);
AudioManager::instance()->SetInputDevice(selected_input);
if (Config::Current()["AudioInput"] != selected_input_name) {
Config::Current()["AudioInput"] = selected_input_name;
AudioManager::instance()->SetInputDevice(selected_input);
}
}
void PreferencesAudioTab::RefreshDevices()
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
dialog/rendercancel/rendercancel.h
dialog/rendercancel/rendercancel.cpp
PARENT_SCOPE
)
+56
View File
@@ -0,0 +1,56 @@
#include "rendercancel.h"
RenderCancelDialog::RenderCancelDialog(QWidget *parent) :
LoadSaveDialog(tr("Waiting for workers to finish..."), tr("Renderer"), parent),
busy_workers_(0),
total_workers_(0)
{
}
void RenderCancelDialog::RunIfWorkersAreBusy()
{
if (busy_workers_ > 0) {
waiting_workers_ = busy_workers_;
exec();
}
}
void RenderCancelDialog::SetWorkerCount(int count)
{
total_workers_ = count;
UpdateProgress();
}
void RenderCancelDialog::WorkerStarted()
{
busy_workers_++;
UpdateProgress();
}
void RenderCancelDialog::WorkerDone()
{
busy_workers_--;
UpdateProgress();
}
void RenderCancelDialog::showEvent(QShowEvent *event)
{
UpdateProgress();
}
void RenderCancelDialog::UpdateProgress()
{
if (!total_workers_ || !isVisible()) {
return;
}
SetProgress(qRound(100.0 * static_cast<double>(waiting_workers_ - busy_workers_) / static_cast<double>(waiting_workers_)));
if (busy_workers_ == 0) {
accept();
}
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef RENDERCANCELDIALOG_H
#define RENDERCANCELDIALOG_H
#include "dialog/loadsave/loadsave.h"
class RenderCancelDialog : public LoadSaveDialog
{
Q_OBJECT
public:
RenderCancelDialog(QWidget* parent = nullptr);
void RunIfWorkersAreBusy();
void SetWorkerCount(int count);
void WorkerStarted();
public slots:
void WorkerDone();
protected:
virtual void showEvent(QShowEvent* event) override;
private:
void UpdateProgress();
int busy_workers_;
int total_workers_;
int waiting_workers_;
};
#endif // RENDERCANCELDIALOG_H