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

Fix possible crashes on invalid track position

parent 63548341
Pipeline #206889 passed with stage
in 7 minutes and 30 seconds
......@@ -1106,7 +1106,7 @@ void TimelineFunctions::setCompositionATrack(const std::shared_ptr<TimelineItemM
QScopedPointer<Mlt::Field> field(timeline->m_tractor->field());
field->lock();
timeline->getCompositionPtr(cid)->setForceTrack(!autoTrack);
timeline->getCompositionPtr(cid)->setATrack(aTrack, aTrack <= 0 ? -1 : timeline->getTrackIndexFromPosition(aTrack - 1));
timeline->getCompositionPtr(cid)->setATrack(aTrack, aTrack < 1 ? -1 : timeline->getTrackIndexFromPosition(aTrack - 1));
field->unlock();
timeline->replantCompositions(cid, true);
emit timeline->invalidateZone(start, end);
......@@ -1118,7 +1118,7 @@ void TimelineFunctions::setCompositionATrack(const std::shared_ptr<TimelineItemM
QScopedPointer<Mlt::Field> field(timeline->m_tractor->field());
field->lock();
timeline->getCompositionPtr(cid)->setForceTrack(previousAutoTrack == 0);
timeline->getCompositionPtr(cid)->setATrack(previousATrack, previousATrack <= 0 ? -1 : timeline->getTrackIndexFromPosition(previousATrack - 1));
timeline->getCompositionPtr(cid)->setATrack(previousATrack, previousATrack < 1 ? -1 : timeline->getTrackIndexFromPosition(previousATrack - 1));
field->unlock();
timeline->replantCompositions(cid, true);
emit timeline->invalidateZone(start, end);
......@@ -1441,6 +1441,9 @@ int TimelineFunctions::getTrackOffset(const std::shared_ptr<TimelineItemModel> &
while (track != destTrackMltIndex) {
track += step;
qDebug() << "+ + +TESTING TRACK: " << track;
if (track < 1) {
continue;
}
int trackId = timeline->getTrackIndexFromPosition(track - 1);
if (isAudio == timeline->isAudioTrack(trackId)) {
offset += step;
......@@ -1460,8 +1463,8 @@ int TimelineFunctions::getOffsetTrackId(const std::shared_ptr<TimelineItemModel>
while (offset != 0) {
masterTrackMltIndex += offset > 0 ? 1 : -1;
qDebug() << "#### TESTING TRACK: " << masterTrackMltIndex;
if (masterTrackMltIndex < 0) {
masterTrackMltIndex = 0;
if (masterTrackMltIndex < 1) {
masterTrackMltIndex = 1;
break;
}
if (masterTrackMltIndex > int(timeline->m_allTracks.size())) {
......
......@@ -4997,7 +4997,7 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
};
int oldAtrack = m_allCompositions[compoId]->getATrack();
delete_reverse = [this, compoId, oldAtrack, updateView]() {
m_allCompositions[compoId]->setATrack(oldAtrack, oldAtrack <= 0 ? -1 : getTrackIndexFromPosition(oldAtrack - 1));
m_allCompositions[compoId]->setATrack(oldAtrack, oldAtrack < 1 ? -1 : getTrackIndexFromPosition(oldAtrack - 1));
return replantCompositions(compoId, updateView);
};
}
......@@ -5025,7 +5025,7 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
Fun insert_reverse = []() { return true; };
if (old_trackId != trackId) {
insert_operation = [this, compoId, compositionTrack, updateView]() {
m_allCompositions[compoId]->setATrack(compositionTrack, compositionTrack <= 0 ? -1 : getTrackIndexFromPosition(compositionTrack - 1));
m_allCompositions[compoId]->setATrack(compositionTrack, compositionTrack < 1 ? -1 : getTrackIndexFromPosition(compositionTrack - 1));
return replantCompositions(compoId, updateView);
};
insert_reverse = [this, compoId]() {
......@@ -6104,7 +6104,7 @@ void TimelineModel::switchComposition(int cid, const QString &compoId)
int newId = -1;
// Check if composition should be reversed (top clip at beginning, bottom at end)
int topClip = getTrackById_const(currentTrack)->getClipByPosition(currentPos);
int bottomTid = getTrackIndexFromPosition(a_track - 1);
int bottomTid = a_track < 1 ? -1 : getTrackIndexFromPosition(a_track - 1);
int bottomClip = -1;
if (bottomTid > -1) {
bottomClip = getTrackById_const(bottomTid)->getClipByPosition(currentPos);
......
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