Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix crash on track insert undo

Fix composition track after track insert
parent ac5a8a4e
Pipeline #9626 passed with stage
in 13 minutes and 34 seconds
......@@ -2123,6 +2123,10 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
if (position < 0 || position > (int)m_allTracks.size()) {
return false;
}
int previousId = -1;
if (position < (int)m_allTracks.size()) {
previousId = getTrackIndexFromPosition(position);
}
int trackId = TimelineModel::getNextId();
id = trackId;
Fun local_undo = deregisterTrack_lambda(trackId, true);
......@@ -2130,11 +2134,24 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
if (updateView) {
_resetView();
}
// Adjust compositions that were affecting track at previous pos
Fun local_update = [previousId, position, this]() {
if (previousId > -1) {
for (auto &compo : m_allCompositions) {
if (compo.second->getATrack() == position && !compo.second->getForcedTrack() > -1) {
compo.second->setATrack(position + 1, previousId);
}
}
}
return true;
};
local_update();
auto track = getTrackById(trackId);
Fun local_redo = [track, position, updateView, this]() {
Fun local_redo = [track, position, updateView, local_update, this]() {
// We capture a shared_ptr to the track, which means that as long as this undo object lives, the track object is not deleted. To insert it back it is
// sufficient to register it.
registerTrack(track, position, true);
local_update();
if (updateView) {
_resetView();
}
......@@ -2259,6 +2276,7 @@ Fun TimelineModel::deregisterTrack_lambda(int id, bool updateView)
{
return [this, id, updateView]() {
// qDebug() << "DEREGISTER TRACK" << id;
emit checkTrackDeletion(id);
auto it = m_iteratorTable[id]; // iterator to the element
int index = getTrackPosition(id); // compute index in list
m_tractor->remove_track(static_cast<int>(index + 1)); // melt operation, add 1 to account for black background track
......
......@@ -767,6 +767,8 @@ signals:
/* @brief Signal sent whenever the selection changes */
void selectionChanged();
/* @brief Signal when a track is deleted so we make sure we don't store its id */
void checkTrackDeletion(int tid);
protected:
std::unique_ptr<Mlt::Tractor> m_tractor;
......
......@@ -105,6 +105,7 @@ void TimelineController::setModel(std::shared_ptr<TimelineItemModel> model)
connect(m_model.get(), &TimelineModel::invalidateZone, this, &TimelineController::invalidateZone, Qt::DirectConnection);
connect(m_model.get(), &TimelineModel::durationUpdated, this, &TimelineController::checkDuration);
connect(m_model.get(), &TimelineModel::selectionChanged, this, &TimelineController::selectionChanged);
connect(m_model.get(), &TimelineModel::checkTrackDeletion, this, &TimelineController::checkTrackDeletion, Qt::DirectConnection);
}
void TimelineController::setTargetTracks(bool hasVideo, QList <int> audioTargets)
......@@ -601,7 +602,17 @@ void TimelineController::deleteTrack(int tid)
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow(), true);
if (d->exec() == QDialog::Accepted) {
int selectedTrackIx = d->selectedTrackId();
if (m_activeTrack == selectedTrackIx) {
m_model->requestTrackDeletion(selectedTrackIx);
m_model->buildTrackCompositing(true);
if (m_activeTrack == -1) {
setActiveTrack(m_model->getTrackIndexFromPosition(m_model->getTracksCount() - 1));
}
}
}
void TimelineController::checkTrackDeletion(int selectedTrackIx)
{
if (m_activeTrack == selectedTrackIx) {
// Make sure we don't keep an index on a deleted track
m_activeTrack = -1;
}
......@@ -619,12 +630,6 @@ void TimelineController::deleteTrack(int tid)
m_lastVideoTarget = -1;
emit lastVideoTargetChanged();
}
m_model->requestTrackDeletion(selectedTrackIx);
m_model->buildTrackCompositing(true);
if (m_activeTrack == -1) {
setActiveTrack(m_model->getTrackIndexFromPosition(m_model->getTracksCount() - 1));
}
}
}
void TimelineController::showConfig(int page, int tab)
......
......@@ -470,6 +470,8 @@ public:
bool dragOperationRunning();
/** @brief Disconnect some stuff before closing project */
void prepareClose();
/** @brief Check that we don't keep a deleted track id */
void checkTrackDeletion(int selectedTrackIx);
public slots:
void resetView();
......
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