From: Jean-Baptiste Mardelle Date: Thu, 1 Oct 2009 12:09:46 +0000 (+0000) Subject: Fix another possible crash on clip move: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=ce25f18672d7bfadff24c4a8e23fcafa7282c434;p=kdenlive Fix another possible crash on clip move: http://www.kdenlive.org/mantis/view.php?id=1171 svn path=/trunk/kdenlive/; revision=3971 --- diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 4d23ec71..1a831846 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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 (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 (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(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 8a5289d5..27f84e5a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -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) diff --git a/src/renderer.h b/src/renderer.h index f1790149..c4d683ef 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -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 trackClipStartList, QMap 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