Fix various crashes on projecr opening

parent d004f658
......@@ -484,6 +484,7 @@ bool ProjectItemModel::addItem(std::shared_ptr<AbstractProjectItem> item, const
return false;
}
Fun operation = addItem_lambda(item, parentItem->getId());
int itemId = item->getId();
Fun reverse = removeItem_lambda(itemId);
bool res = operation();
......@@ -805,6 +806,7 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
*/
} else {
QString newId = isIdFree(id) ? id : QString::number(getFreeClipId());
producer->set("_kdenlive_processed", 1);
requestAddBinClip(newId, producer, parentId, undo, redo);
binIdCorresp[id] = newId;
qDebug() << "Loaded clip "<< id <<"under id"<<newId;
......
......@@ -396,7 +396,7 @@ int Core::getItemTrack(const ObjectId &id)
void Core::refreshProjectItem(const ObjectId &id)
{
if (!m_guiConstructed) return;
if (!m_guiConstructed || m_mainWindow->getCurrentTimeline()->loading) return;
switch (id.first) {
case ObjectType::TimelineClip:
if (m_mainWindow->getCurrentTimeline()->controller()->getModel()->isClip(id.second)) {
......@@ -503,7 +503,7 @@ std::shared_ptr<ProjectItemModel> Core::projectItemModel()
void Core::invalidateItem(ObjectId itemId)
{
if (!m_mainWindow) return;
if (!m_mainWindow || m_mainWindow->getCurrentTimeline()->loading) return;
switch (itemId.first) {
case ObjectType::TimelineClip:
m_mainWindow->getCurrentTimeline()->controller()->invalidateClip(itemId.second);
......@@ -531,7 +531,7 @@ void Core::updateItemKeyframes(ObjectId id)
void Core::updateItemModel(ObjectId id, const QString &service)
{
if (service.startsWith(QLatin1String("fade")) && id.first == ObjectType::TimelineClip) {
if (!m_mainWindow->getCurrentTimeline()->loading && service.startsWith(QLatin1String("fade")) && id.first == ObjectType::TimelineClip) {
bool startFade = service == QLatin1String("fadein") || service == QLatin1String("fade_from_black");
m_mainWindow->getCurrentTimeline()->controller()->updateClip(id.second, {startFade ?TimelineModel::FadeInRole : TimelineModel::FadeOutRole});
}
......
......@@ -865,7 +865,13 @@ void ProjectManager::slotMoveFinished(KJob *job)
void ProjectManager::updateTimeline(int pos)
{
pCore->jobManager()->slotCancelJobs();
qDebug() << "Loading xml"<<m_project->getProjectXml().constData();
/*qDebug() << "Loading xml"<<m_project->getProjectXml().constData();
QFile file("/tmp/data.xml");
if (file.open(QIODevice::ReadWrite)) {
QTextStream stream(&file);
stream << m_project->getProjectXml() << endl;
}*/
pCore->window()->getMainTimeline()->loading = true;
QScopedPointer<Mlt::Producer> xmlProd(new Mlt::Producer(pCore->getCurrentProfile()->profile(), "xml-string", m_project->getProjectXml().constData()));
Mlt::Service s(*xmlProd);
Mlt::Tractor tractor(s);
......
......@@ -45,7 +45,6 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
Fun redo = []() { return true; };
// First, we destruct the previous tracks
timeline->requestReset(undo, redo);
std::unordered_map<QString, QString> binIdCorresp;
pCore->projectItemModel()->loadBinPlaylist(&tractor, timeline->tractor(), binIdCorresp);
......@@ -169,9 +168,15 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
switch (clip->type()) {
case unknown_type:
case producer_type: {
qDebug() << "Looking for clip clip "<< clip->parent().get("kdenlive:id");
Q_ASSERT(binIdCorresp.count(clip->parent().get("kdenlive:id")) > 0);
QString binId = binIdCorresp.at(QString(clip->parent().get("kdenlive:id")));
//qDebug() << "Looking for clip clip "<< clip->parent().get("kdenlive:id")<<" = "<<clip->parent().get("kdenlive:clipname");
QString binId;
if (clip->parent().get_int("_kdenlive_processed") == 1) {
// This is a bin clip, already processed no need to change id
binId = QString(clip->parent().get("kdenlive:id"));
} else {
Q_ASSERT(binIdCorresp.count(clip->parent().get("kdenlive:id")) > 0);
binId = binIdCorresp.at(QString(clip->parent().get("kdenlive:id")));
}
bool ok = false;
if (pCore->bin()->getBinClip(binId)) {
int cid = ClipModel::construct(timeline, binId, clip);
......
......@@ -893,7 +893,6 @@ void TimelineController::startPreviewRender()
if (m_timelinePreview) {
if (!m_usePreview) {
m_timelinePreview->buildPreviewTrack();
qDebug() << "// STARTING PREVIEW TRACK";
m_usePreview = true;
m_model->m_overlayTrackCount = m_timelinePreview->addedTracks();
}
......@@ -999,6 +998,8 @@ void TimelineController::loadPreview(QString chunks, QString dirty, const QDateT
m_disablePreview->blockSignals(false);
if (!enable) {
m_timelinePreview->buildPreviewTrack();
m_usePreview = true;
m_model->m_overlayTrackCount = m_timelinePreview->addedTracks();
}
m_timelinePreview->loadChunks(renderedChunks, dirtyChunks, documentDate);
}
......
......@@ -52,7 +52,6 @@ TimelineWidget::TimelineWidget(KActionCollection *actionCollection, QWidget *par
{
registerTimelineItems();
m_transitionModel = TransitionTreeModel::construct(true, this);
m_transitionProxyModel.reset(new AssetFilter(this));
m_transitionProxyModel->setSourceModel(m_transitionModel.get());
m_transitionProxyModel->setSortRole(AssetTreeModel::NameRole);
......@@ -92,6 +91,7 @@ void TimelineWidget::setModel(std::shared_ptr<TimelineItemModel> model)
connect(rootObject(), SIGNAL(mousePosChanged(int)), pCore->window(), SLOT(slotUpdateMousePosition(int)));
m_proxy->setRoot(rootObject());
setVisible(true);
loading = false;
m_proxy->setActiveTrack(model->getTrackIndexFromPosition(model->getTracksCount() - 1));
m_proxy->checkDuration();
}
......
......@@ -48,6 +48,7 @@ public:
TimelineController *controller();
void setTool(ProjectTool tool);
QPoint getTracksCount() const;
bool loading;
protected:
void mousePressEvent(QMouseEvent *event) override;
......
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