diff --git a/src/commands/timelinecommands.cpp b/src/commands/timelinecommands.cpp index 8686eb39e5..616a64de58 100644 --- a/src/commands/timelinecommands.cpp +++ b/src/commands/timelinecommands.cpp @@ -1493,12 +1493,15 @@ void AddTrackCommand::redo() else m_trackIndex = m_model.addAudioTrack(); int mlt_index = m_model.trackList().at(m_trackIndex).mlt_index; - Mlt::Producer producer(m_model.tractor()->multitrack()->track(mlt_index)); - if (producer.is_valid()) { + std::unique_ptr multitrack(m_model.tractor()->multitrack()); + if (!multitrack || !multitrack->is_valid()) + return; + std::unique_ptr producer(multitrack->track(mlt_index)); + if (producer && producer->is_valid()) { if (m_uuid.isNull()) { - m_uuid = MLT.ensureHasUuid(producer); + m_uuid = MLT.ensureHasUuid(*producer); } else { - MLT.setUuid(producer, m_uuid); + MLT.setUuid(*producer, m_uuid); } } } @@ -1532,12 +1535,15 @@ void InsertTrackCommand::redo() "video"); m_model.insertTrack(m_trackIndex, m_trackType); int mlt_index = m_model.trackList().at(m_trackIndex).mlt_index; - Mlt::Producer producer(m_model.tractor()->multitrack()->track(mlt_index)); - if (producer.is_valid()) { + std::unique_ptr multitrack(m_model.tractor()->multitrack()); + if (!multitrack || !multitrack->is_valid()) + return; + std::unique_ptr producer(multitrack->track(mlt_index)); + if (producer && producer->is_valid()) { if (m_uuid.isNull()) { - m_uuid = MLT.ensureHasUuid(producer); + m_uuid = MLT.ensureHasUuid(*producer); } else { - MLT.setUuid(producer, m_uuid); + MLT.setUuid(*producer, m_uuid); } } } @@ -1839,12 +1845,15 @@ void DetachAudioCommand::redo() if (m_targetTrackIndex > -1) { // Set the producer UUID on the new track. int mlt_index = model->trackList().at(m_targetTrackIndex).mlt_index; - Mlt::Producer producer(model->tractor()->multitrack()->track(mlt_index)); - if (producer.is_valid()) { - if (m_uuid.isNull()) { - m_uuid = MLT.ensureHasUuid(producer); - } else { - MLT.setUuid(producer, m_uuid); + std::unique_ptr multitrack(model->tractor()->multitrack()); + if (multitrack && !multitrack->is_valid()) { + std::unique_ptr producer(multitrack->track(mlt_index)); + if (producer && producer->is_valid()) { + if (m_uuid.isNull()) { + m_uuid = MLT.ensureHasUuid(*producer); + } else { + MLT.setUuid(*producer, m_uuid); + } } } m_undoHelper.recordBeforeState(); diff --git a/src/docks/timelinedock.cpp b/src/docks/timelinedock.cpp index 367c4c6907..93fefc6db5 100644 --- a/src/docks/timelinedock.cpp +++ b/src/docks/timelinedock.cpp @@ -2539,12 +2539,11 @@ void TimelineDock::emitSelectedFromSelection() if (selection().isEmpty() && m_selection.selectedTrack > -1) { int i = m_model.trackList().at(m_selection.selectedTrack).mlt_index; - Mlt::Producer *producer = m_model.tractor()->track(i); + std::unique_ptrproducer(m_model.tractor()->track(i)); if (producer && producer->is_valid()) { producer->set(kTrackIndexProperty, m_selection.selectedTrack); - emit selected(producer); + emit selected(producer.get()); } - delete producer; return; } diff --git a/src/models/multitrackmodel.cpp b/src/models/multitrackmodel.cpp index a8f5c78013..30b8eac3b1 100644 --- a/src/models/multitrackmodel.cpp +++ b/src/models/multitrackmodel.cpp @@ -2467,12 +2467,11 @@ void MultitrackModel::consolidateBlanksAllTracks() if (!m_tractor) return; int i = 0; foreach (Track t, m_trackList) { - Mlt::Producer *track = m_tractor->track(t.mlt_index); - if (track) { + std::unique_ptr track(m_tractor->track(t.mlt_index)); + if (track && track->is_valid()) { Mlt::Playlist playlist(*track); consolidateBlanks(playlist, i); } - delete track; ++i; } } @@ -2518,11 +2517,11 @@ void MultitrackModel::adjustBackgroundDuration() { if (!m_tractor) return; int duration = getDuration(); - Mlt::Producer *track = m_tractor->track(0); - if (track) { + std::unique_ptr track(m_tractor->track(0)); + if (track && track->is_valid()) { Mlt::Playlist playlist(*track); - Mlt::Producer *clip = playlist.get_clip(0); - if (clip) { + std::unique_ptr clip(playlist.get_clip(0)); + if (clip && clip->is_valid()) { if (duration != clip->parent().get_length()) { clip->parent().set("length", clip->parent().frames_to_time(duration, mlt_time_clock)); clip->parent().set_in_and_out(0, duration - 1); @@ -2531,9 +2530,7 @@ void MultitrackModel::adjustBackgroundDuration() playlist.resize_clip(0, 0, duration - 1); emit durationChanged(); } - delete clip; } - delete track; } } @@ -3651,10 +3648,9 @@ void MultitrackModel::addBlackTrackIfNeeded() if (!found) { // Move all existing tracks down by 1. for (int i = n; i > 0; i++) { - Mlt::Producer *producer = m_tractor->track(n - 1); - if (producer) + std::unique_ptr producer(m_tractor->track(n - 1)); + if (producer && producer->is_valid()) m_tractor->set_track(*producer, n); - delete producer; } Mlt::Producer producer(MLT.profile(), "color:0"); producer.set("mlt_image_format", "rgba");