Commit 124d7175 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix possible crash when load task is running on exit

parent c4712924
Pipeline #183628 passed with stage
in 11 minutes and 54 seconds
......@@ -740,11 +740,13 @@ void ClipLoadTask::run()
void ClipLoadTask::abort()
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
m_progress = 100;
pCore->taskManager.taskDone(m_owner.second, this);
qDebug() << pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second))->clipUrl();
if (pCore->taskManager.isBlocked()) {
return;
}
Fun undo = []() { return true; };
Fun redo = []() { return true; };
QString resource = Xml::getXmlProperty(m_xml, QStringLiteral("resource"));
if (!m_softDelete) {
auto binClip = pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second));
......
......@@ -22,6 +22,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
TaskManager::TaskManager(QObject *parent)
: QObject(parent)
, m_tasksListLock(QReadWriteLock::Recursive)
, m_blockUpdates(false)
{
int maxThreads = qMin(4, QThread::idealThreadCount() - 1);
m_taskPool.setMaxThreadCount(qMax(maxThreads, 1));
......@@ -33,6 +34,11 @@ TaskManager::~TaskManager()
slotCancelJobs();
}
bool TaskManager::isBlocked() const
{
return m_blockUpdates;
}
void TaskManager::updateConcurrency()
{
m_transcodePool.setMaxThreadCount(KdenliveSettings::proxythreads());
......@@ -128,6 +134,7 @@ void TaskManager::slotCancelJobs(const QVector<AbstractTask::JOBTYPE> exceptions
{
m_tasksListLock.lockForRead();
// See if there is already a task for this MLT service and resource.
m_blockUpdates = true;
for (const auto &task : m_taskList) {
for (AbstractTask *t : task.second) {
if (!exceptions.contains(t->m_type)) {
......@@ -141,6 +148,7 @@ void TaskManager::slotCancelJobs(const QVector<AbstractTask::JOBTYPE> exceptions
m_taskPool.waitForDone();
m_transcodePool.waitForDone();
}
m_blockUpdates = false;
updateJobCount();
}
......
......@@ -63,6 +63,9 @@ public:
/** @brief Update the number of concurrent jobs allowed */
void updateConcurrency();
/** @brief We are aborting all tasks and don't want them to send any updates */
bool isBlocked() const;
/** @brief return the message of a given job on a given clip (message, detailed log)*/
//QPair<QString, QString> getJobMessageForClip(int jobId, const QString &binId) const;
......@@ -79,6 +82,7 @@ private:
QThreadPool m_transcodePool;
std::unordered_map<int, std::vector<AbstractTask*> > m_taskList;
mutable QReadWriteLock m_tasksListLock;
bool m_blockUpdates;
signals:
void jobCount(int);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment