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

Properly release timelinemodel on document close.

CCBUG: 409667
parent 4e6799e0
......@@ -141,6 +141,11 @@ void MixerManager::cleanup()
}
}
void MixerManager::unsetModel()
{
m_model.reset();
}
void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model)
{
// Insert master mixer
......
......@@ -53,6 +53,8 @@ public:
void collapseMixers();
/** @brief Pause/unpause audio monitoring */
void pauseMonitoring(bool pause);
/** @brief Release the timeline model ownership */
void unsetModel();
public slots:
void recordStateChanged(int tid, bool recording);
......
......@@ -44,7 +44,7 @@
SubtitleModel::SubtitleModel(Mlt::Tractor *tractor, std::shared_ptr<TimelineItemModel> timeline, QObject *parent)
: QAbstractListModel(parent)
, m_timeline(std::move(timeline))
, m_timeline(timeline)
, m_lock(QReadWriteLock::Recursive)
, m_subtitleFilter(new Mlt::Filter(pCore->getCurrentProfile()->profile(), "avfilter.subtitles"))
, m_tractor(tractor)
......@@ -79,6 +79,11 @@ void SubtitleModel::setup()
connect(this, &SubtitleModel::modelReset, this, &SubtitleModel::modelChanged);
}
void SubtitleModel::unsetModel()
{
m_timeline.reset();
}
void SubtitleModel::importSubtitle(const QString filePath, int offset, bool externalImport)
{
QString start,end,comment;
......
......@@ -148,6 +148,8 @@ public:
void switchGrab(int sid);
/** @brief Ungrab all items */
void clearGrab();
/** @brief Release timeline model pointer */
void unsetModel();
public slots:
/** @brief Function that parses through a subtitle file */
......
......@@ -40,7 +40,7 @@
SpeechDialog::SpeechDialog(std::shared_ptr<TimelineItemModel> timeline, QPoint zone, bool, bool, QWidget *parent)
: QDialog(parent)
, m_timeline(std::move(timeline))
, m_timeline(timeline)
{
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
......
......@@ -275,7 +275,7 @@ bool ProjectManager::closeCurrentDocument(bool saveChanges, bool quit)
pCore->bin()->abortOperations();
}
}
pCore->window()->getMainTimeline()->controller()->prepareClose();
pCore->window()->getMainTimeline()->unsetModel();
pCore->bin()->cleanDocument();
pCore->window()->resetSubtitles();
if (m_mainTimelineModel) {
......@@ -289,6 +289,8 @@ bool ProjectManager::closeCurrentDocument(bool saveChanges, bool quit)
m_project = nullptr;
}
}
pCore->mixer()->unsetModel();
// Release model shared pointers
m_mainTimelineModel.reset();
return true;
}
......
......@@ -3612,10 +3612,11 @@ void TimelineModel::registerGroup(int groupId)
Fun TimelineModel::deregisterTrack_lambda(int id)
{
return [this, id]() {
emit checkTrackDeletion(id);
if (!m_closing) {
emit checkTrackDeletion(id);
}
auto it = m_iteratorTable[id]; // iterator to the element
int index = getTrackPosition(id); // compute index in list
// send update to the model
beginRemoveRows(QModelIndex(), index, index);
// melt operation, add 1 to account for black background track
......@@ -3626,8 +3627,10 @@ Fun TimelineModel::deregisterTrack_lambda(int id)
m_iteratorTable.erase(id);
// Finish operation
endRemoveRows();
int cache = int(QThread::idealThreadCount()) + int(m_allTracks.size() + 1) * 2;
mlt_service_cache_set_size(nullptr, "producer_avformat", qMax(4, cache));
if (!m_closing) {
int cache = int(QThread::idealThreadCount()) + int(m_allTracks.size() + 1) * 2;
mlt_service_cache_set_size(nullptr, "producer_avformat", qMax(4, cache));
}
return true;
};
}
......@@ -3637,7 +3640,9 @@ Fun TimelineModel::deregisterClip_lambda(int clipId)
return [this, clipId]() {
// Clear effect stack
clearAssetView(clipId);
emit checkItemDeletion(clipId);
if (!m_closing) {
emit checkItemDeletion(clipId);
}
Q_ASSERT(m_allClips.count(clipId) > 0);
Q_ASSERT(getClipTrackId(clipId) == -1); // clip must be deleted from its track at this point
Q_ASSERT(!m_groups->isInGroup(clipId)); // clip must be ungrouped at this point
......
......@@ -100,6 +100,7 @@ void TimelineController::prepareClose()
QObject::disconnect( m_deleteConnection );
m_ready = false;
m_root = nullptr;
m_model.reset();
// Delete timeline preview before resetting model so that removing clips from timeline doesn't invalidate
delete m_timelinePreview;
m_timelinePreview = nullptr;
......
......@@ -156,6 +156,12 @@ void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QM
m_timelineMenu->addMenu(m_favCompositions);
}
void TimelineWidget::unsetModel()
{
m_sortModel->setSourceModel(nullptr);
m_proxy->prepareClose();
}
void TimelineWidget::setModel(const std::shared_ptr<TimelineItemModel> &model, MonitorProxy *proxy)
{
m_sortModel->setSourceModel(model.get());
......
......@@ -58,6 +58,7 @@ public:
bool loading;
void connectSubtitleModel(bool firstConnect);
void regainFocus();
void unsetModel();
protected:
void mousePressEvent(QMouseEvent *event) override;
......
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