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

Don't crash loading project with incorrect subtrack count

parent 13ae5abe
Pipeline #207630 passed with stage
in 6 minutes and 30 seconds
......@@ -1024,6 +1024,21 @@ void ProjectManager::slotMoveFinished(KJob *job)
}
}
void ProjectManager::requestBackup(const QString &errorMessage)
{
KMessageBox::ButtonCode res = KMessageBox::warningContinueCancel(qApp->activeWindow(), errorMessage);
pCore->window()->getMainTimeline()->loading = false;
m_project->setModified(false);
if (res == KMessageBox::Continue) {
// Try opening backup
if (!slotOpenBackup(m_project->url())) {
newFile(false);
}
} else {
newFile(false);
}
}
bool ProjectManager::updateTimeline(int pos, const QString &chunks, const QString &dirty, const QDateTime &documentDate, int enablePreview)
{
pCore->taskManager.slotCancelJobs();
......@@ -1037,18 +1052,7 @@ bool ProjectManager::updateTimeline(int pos, const QString &chunks, const QStrin
Mlt::Tractor tractor(s);
if (tractor.count() == 0) {
// Wow we have a project file with empty tractor, probably corrupted, propose to open a recovery file
KMessageBox::ButtonCode res =
KMessageBox::warningContinueCancel(qApp->activeWindow(), i18n("Project file is corrupted (no tracks). Try to find a backup file?"));
pCore->window()->getMainTimeline()->loading = false;
m_project->setModified(false);
if (res == KMessageBox::Continue) {
// Try opening backup
if (!slotOpenBackup(m_project->url())) {
newFile(false);
}
} else {
newFile(false);
}
requestBackup(i18n("Project file is corrupted (no tracks). Try to find a backup file?"));
return false;
}
m_mainTimelineModel = TimelineItemModel::construct(pCore->getProjectProfile(), m_project->getGuideModel(), m_project->commandStack());
......@@ -1061,6 +1065,8 @@ bool ProjectManager::updateTimeline(int pos, const QString &chunks, const QStrin
&projectErrors)) {
// TODO: act on project load failure
qDebug() << "// Project failed to load!!";
requestBackup(i18n("Project file is corrupted (no tracks). Try to find a backup file?"));
return false;
}
// Free memory used by original playlist
xmlProd->clear();
......
......@@ -213,4 +213,6 @@ private:
/** @brief If true, means we are still opening Kdenlive, send messages to splash screen */
bool m_loading{false};
void saveRecentFiles();
/** @brief Project loading failed, ask user if he wants to open a backup */
void requestBackup(const QString &errorMessage);
};
......@@ -262,9 +262,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
}
if (!ok) {
// TODO log error
// Don't abort loading because of failed composition
undo();
// Loading tracks failed, abort loading
return false;
}
if (!qEnvironmentVariableIsSet("MLT_TESTS")) {
......
......@@ -4104,7 +4104,7 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
_resetView();
} else {
if (audioTrack) {
for (int i = 0; i <= position; i++) {
for (int i = 0; i <= position && i < int(m_allTracks.size()); i++) {
QModelIndex ix = makeTrackIndexFromID(getTrackIndexFromPosition(i));
emit dataChanged(ix, ix, {TimelineModel::TrackTagRole});
}
......
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