]> git.sesse.net Git - kdenlive/commitdiff
Fix another possible crash on clip move:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 1 Oct 2009 12:09:46 +0000 (12:09 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 1 Oct 2009 12:09:46 +0000 (12:09 +0000)
http://www.kdenlive.org/mantis/view.php?id=1171

svn path=/trunk/kdenlive/; revision=3971

src/customtrackview.cpp
src/renderer.cpp
src/renderer.h

index 4d23ec715ffa44773456692dbbfff33d958312aa..1a831846ad33e444aeba4fc03355b88ed032a5e4 100644 (file)
@@ -2076,7 +2076,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                     if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
                     else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
                     else prod = clip->baseClip()->producer(clipinfo.track);
-                    m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod);
+                    if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
+                        // problem updating clip
+                        emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
+                    }
                 }
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition *>(item);
@@ -2146,7 +2149,9 @@ void CustomTrackView::removeTrack(int ix)
                 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
                 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
                 else prod = clip->baseClip()->producer(clipinfo.track);
-                m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod);
+                if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
+                }
             }
         } else if (children.at(i)->type() == TRANSITIONWIDGET) {
             Transition *tr = static_cast <Transition *>(children.at(i));
@@ -3357,7 +3362,9 @@ void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
             if (clip->clipProducer() == clipId) {
                 ItemInfo info = clip->info();
                 info.track = m_document->tracksCount() - clip->track();
-                if (reload) m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer());
+                if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
+                }
                 clip->refreshClip(true);
                 clip->update();
             }
@@ -4859,8 +4866,12 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
             ClipItem *audioClip = getClipItemAt(start, info.track);
             if (audioClip) {
                 clip->setVideoOnly(true);
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer());
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track));
+                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
+                }
+                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
+                }
                 audioClip->setSelected(true);
                 audioClip->setAudioOnly(true);
                 groupSelectedItems(false, true);
@@ -4884,7 +4895,9 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
                 ItemInfo info = clip->info();
                 deleteClip(clp->info());
                 clip->setVideoOnly(false);
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track));
+                if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
+                }
                 break;
             }
         }
@@ -4980,17 +4993,23 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video
         int start = pos.frames(m_document->fps());
         clip->setVideoOnly(true);
         clip->setAudioOnly(false);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer());
+        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
+            emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
+        }
     } else if (audioOnly) {
         int start = pos.frames(m_document->fps());
         clip->setAudioOnly(true);
         clip->setVideoOnly(false);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track));
+        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
+            emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
+        }
     } else {
         int start = pos.frames(m_document->fps());
         clip->setAudioOnly(false);
         clip->setVideoOnly(false);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track));
+        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) {
+            emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
+        }
     }
     clip->update();
     setDocumentModified();
index 8a5289d51a52ce0a15494c98428d45988a050afa..27f84e5ace1898748792f0203ccd8e87609861c1 100644 (file)
@@ -1539,6 +1539,10 @@ int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pro
         kDebug() << "PLAYLIST NOT INITIALISED //////";
         return -1;
     }
+    if (prod == NULL) {
+        kDebug() << "Cannot insert clip without producer //////";
+        return -1;
+    }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
         kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
@@ -1682,13 +1686,17 @@ void Render::mltCutClip(int track, GenTime position)
     m_isBlocked = false;
 }
 
-void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
+bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
 {
     // TODO: optimize
+    if (prod == NULL) {
+        kDebug() << "Cannot update clip with null producer //////";
+        return false;
+    }
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) {
         kWarning() << "// TRACTOR PROBLEM";
-        return;
+        return false;
     }
     Mlt::Tractor tractor(service);
     Mlt::Producer trackProducer(tractor.track(info.track));
@@ -1709,8 +1717,8 @@ void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
         ct++;
         filter = sourceService.filter(ct);
     }
-    mltRemoveClip(info.track, info.startPos);
-    mltInsertClip(info, element, prod);
+    if (!mltRemoveClip(info.track, info.startPos)) return false;
+    if (mltInsertClip(info, element, prod) == -1) return false;
     if (!filtersList.isEmpty()) {
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
@@ -1719,6 +1727,7 @@ void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
         for (int i = 0; i < filtersList.count(); i++)
             destService.attach(*(filtersList.at(i)));
     }
+    return true;
 }
 
 
@@ -2710,11 +2719,11 @@ bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTim
 }
 
 
-void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
+bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
 {
     if (prod == NULL || !prod->is_valid()) {
         kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
-        return;
+        return false;
     }
     kDebug() << "NEW PROD ID: " << prod->get("id");
     m_isBlocked++;
@@ -2722,7 +2731,7 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) {
         kWarning() << "// TRACTOR PROBLEM";
-        return;
+        return false;
     }
     mlt_service_lock(m_mltConsumer->get_service());
 
@@ -2736,10 +2745,10 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
         delete clipProducer;
         mlt_service_unlock(m_mltConsumer->get_service());
         m_isBlocked--;
-        return;
+        return false;
     }
     Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
-
+    if (!clip) return false;
     // move all effects to the correct producer
     mltPasteEffects(clipProducer, clip);
     trackPlaylist.insert_at(pos, clip, 1);
@@ -2747,6 +2756,7 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
     delete clipProducer;
     mlt_service_unlock(m_mltConsumer->get_service());
     m_isBlocked--;
+    return true;
 }
 
 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
index f1790149555dbf504f243e8d3593b459204dc08e..c4d683efbaa1c5c6c62703ed11f11afe7685a519 100644 (file)
@@ -170,7 +170,7 @@ Q_OBJECT public:
 
     /** Playlist manipulation */
     int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
-    void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
+    bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
     void mltCutClip(int track, GenTime position);
     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
@@ -204,7 +204,7 @@ Q_OBJECT public:
     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
     void mltInsertTrack(int ix, bool videoTrack);
     void mltDeleteTrack(int ix);
-    void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
+    bool mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
 
     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path