Fix thread/cache count causing concurrency crashes.

Fixes #265
parent 8f533d9c
Pipeline #4486 passed with stage
in 14 minutes and 7 seconds
......@@ -53,6 +53,7 @@ Core::Core()
void Core::prepareShutdown()
{
m_guiConstructed = false;
QThreadPool::globalInstance()->clear();
}
Core::~Core()
......@@ -195,6 +196,7 @@ void Core::initGUI(const QUrl &Url)
}
QMetaObject::invokeMethod(pCore->projectManager(), "slotLoadOnOpen", Qt::QueuedConnection);
m_mainWindow->show();
QThreadPool::globalInstance()->setMaxThreadCount(qMin(4, QThreadPool::globalInstance()->maxThreadCount()));
}
std::unique_ptr<Core> &Core::self()
......
......@@ -37,6 +37,7 @@
#include "trackmodel.hpp"
#include <QDebug>
#include <QThread>
#include <QModelIndex>
#include <klocalizedstring.h>
#include <mlt++/MltConsumer.h>
......@@ -2077,6 +2078,8 @@ void TimelineModel::registerTrack(std::shared_ptr<TrackModel> track, int pos, bo
// it now contains the iterator to the inserted element, we store it
Q_ASSERT(m_iteratorTable.count(id) == 0); // check that id is not used (shouldn't happen)
m_iteratorTable[id] = it;
int cache = QThread::idealThreadCount() + (m_allTracks.size() + 1) * 2;
mlt_service_cache_set_size(NULL, "producer_avformat", qMax(4, cache));
}
void TimelineModel::registerClip(const std::shared_ptr<ClipModel> &clip, bool registerProducer)
......@@ -2109,6 +2112,8 @@ Fun TimelineModel::deregisterTrack_lambda(int id, bool updateView)
if (updateView) {
_resetView();
}
int cache = QThread::idealThreadCount() + (m_allTracks.size() + 1) * 2;
mlt_service_cache_set_size(NULL, "producer_avformat", qMax(4, cache));
return true;
};
}
......
......@@ -518,6 +518,7 @@ Fun TrackModel::requestClipResize_lambda(int clipId, int in, int out, bool right
int target_clip_mutable = target_clip;
int blank_index = right ? (target_clip_mutable + 1) : target_clip_mutable;
// insert blank to space that is going to be empty
m_playlists[target_track].lock();
// The second is parameter is delta - 1 because this function expects an out time, which is basically size - 1
m_playlists[target_track].insert_blank(blank_index, delta - 1);
if (!right) {
......@@ -528,6 +529,7 @@ Fun TrackModel::requestClipResize_lambda(int clipId, int in, int out, bool right
int err = m_playlists[target_track].resize_clip(target_clip_mutable, in, out);
// make sure to do this after, to avoid messing the indexes
m_playlists[target_track].consolidate_blanks();
m_playlists[target_track].unlock();
if (err == 0) {
update_snaps(m_allClips[clipId]->getPosition(), m_allClips[clipId]->getPosition() + out - in + 1);
if (right && m_playlists[target_track].count() - 1 == target_clip_mutable) {
......@@ -584,6 +586,7 @@ Fun TrackModel::requestClipResize_lambda(int clipId, int in, int out, bool right
if (isLocked()) return false;
int target_clip_mutable = target_clip;
int err = 0;
m_playlists[target_track].lock();
if (blank_length + delta == 0) {
err = m_playlists[target_track].remove(blank);
if (!right) {
......@@ -608,6 +611,7 @@ Fun TrackModel::requestClipResize_lambda(int clipId, int in, int out, bool right
update_snaps(m_allClips[clipId]->getPosition(), m_allClips[clipId]->getPosition() + out - in + 1);
}
m_playlists[target_track].consolidate_blanks();
m_playlists[target_track].unlock();
return err == 0;
};
}
......
Markdown is supported
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