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

Fix crash when clip is modified by external app

parent 6c52d311
Pipeline #228952 skipped
......@@ -13,7 +13,7 @@ FileWatcher::FileWatcher(QObject *parent)
, m_fileWatcher(new KDirWatch)
{
// Init clip modification tracker
m_modifiedTimer.setInterval(1500);
m_modifiedTimer.setInterval(2000);
connect(m_fileWatcher.get(), &KDirWatch::dirty, this, &FileWatcher::slotUrlModified);
connect(m_fileWatcher.get(), &KDirWatch::deleted, this, &FileWatcher::slotUrlMissing);
connect(m_fileWatcher.get(), &KDirWatch::created, this, &FileWatcher::slotUrlAdded);
......
......@@ -71,6 +71,7 @@ RTTR_REGISTRATION
ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model, std::shared_ptr<Mlt::Producer> producer)
: AbstractProjectItem(AbstractProjectItem::ClipItem, id, model)
, ClipController(id, producer)
, isReloading(false)
, m_resetTimelineOccurences(false)
, m_audioCount(0)
, m_uuid(QUuid::createUuid())
......@@ -142,6 +143,7 @@ void ProjectClip::importEffects(const std::shared_ptr<Mlt::Producer> &producer,
ProjectClip::ProjectClip(const QString &id, const QDomElement &description, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model)
: AbstractProjectItem(AbstractProjectItem::ClipItem, id, model)
, ClipController(id)
, isReloading(false)
, m_resetTimelineOccurences(false)
, m_audioCount(0)
, m_uuid(QUuid::createUuid())
......@@ -423,6 +425,7 @@ void ProjectClip::reloadProducer(bool refreshOnly, bool isProxy, bool forceAudio
}
}
m_audioThumbCreated = false;
isReloading = true;
// Reset uuid to enforce reloading thumbnails from qml cache
m_uuid = QUuid::createUuid();
if (forceAudioReload || (!isProxy && hashChanged)) {
......@@ -539,6 +542,7 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool gene
}
// Make sure we have a hash for this clip
updateProducer(producer);
isReloading = false;
getFileHash();
emit producerChanged(m_binId, producer);
m_thumbsProducer.reset();
......
......@@ -69,6 +69,11 @@ public:
*/
const QString getProxyFromOriginal(QString originalPath) const;
/**
* @brief True if we started a clip reload
*/
bool isReloading;
protected:
ProjectClip(const QString &id, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model, std::shared_ptr<Mlt::Producer> producer);
ProjectClip(const QString &id, const QDomElement &description, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model);
......
......@@ -480,9 +480,12 @@ void ClipLoadTask::run()
if (producer) {
producer.reset();
}
QMetaObject::invokeMethod(pCore.get(), "displayBinMessage", Qt::QueuedConnection,
Q_ARG(QString, m_errorMessage.isEmpty() ? i18n("Cannot open file %1", resource) : m_errorMessage),
Q_ARG(int, int(KMessageWidget::Warning)));
auto binClip = pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second));
if (binClip && !binClip->isReloading) {
QMetaObject::invokeMethod(pCore.get(), "displayBinMessage", Qt::QueuedConnection,
Q_ARG(QString, m_errorMessage.isEmpty() ? i18n("Cannot open file %1", resource) : m_errorMessage),
Q_ARG(int, int(KMessageWidget::Warning)));
}
emit taskDone();
abort();
return;
......@@ -761,7 +764,7 @@ void ClipLoadTask::abort()
auto binClip = pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second));
if (binClip) {
QMetaObject::invokeMethod(binClip.get(), "setInvalid", Qt::QueuedConnection);
if (!m_isCanceled.loadAcquire()) {
if (!m_isCanceled.loadAcquire() && !binClip->isReloading) {
// User tried to add an invalid clip, remove it.
pCore->projectItemModel()->requestBinClipDeletion(binClip, undo, redo);
} else {
......
......@@ -81,8 +81,10 @@ void FilterTask::run()
}
if ((producer == nullptr) || !producer->is_valid()) {
// Clip was removed or something went wrong
QMetaObject::invokeMethod(pCore.get(), "displayBinMessage", Qt::QueuedConnection, Q_ARG(QString, i18n("Cannot open file %1", binClip->url())),
Q_ARG(int, int(KMessageWidget::Warning)));
if (!binClip->isReloading) {
QMetaObject::invokeMethod(pCore.get(), "displayBinMessage", Qt::QueuedConnection, Q_ARG(QString, i18n("Cannot open file %1", binClip->url())),
Q_ARG(int, int(KMessageWidget::Warning)));
}
pCore->taskManager.taskDone(m_owner.second, this);
return;
}
......
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