From 6e639f6a6c1afd5709efcb0998a3fa93d40e8b8b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 20 Nov 2020 13:13:05 +0100 Subject: [PATCH] Fix crash on adding first subtitle from subtitle widget --- src/core.cpp | 9 +++++++-- src/core.h | 2 +- src/timeline2/view/timelinecontroller.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 4a76aedfe..95fa9dd9a 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -283,10 +283,15 @@ void Core::selectTimelineItem(int id) } } -std::shared_ptr Core::getSubtitleModel() +std::shared_ptr Core::getSubtitleModel(bool enforce) { if (m_guiConstructed && m_mainWindow->getCurrentTimeline()->controller()->getModel()) { - return m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + auto subModel = m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + if (enforce && subModel == nullptr) { + m_mainWindow->slotEditSubtitle(); + subModel = m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + } + return subModel; } return nullptr; } diff --git a/src/core.h b/src/core.h index 7969cdead..621babd8d 100644 --- a/src/core.h +++ b/src/core.h @@ -238,7 +238,7 @@ public: /** @brief Temporarily un/plug a list of clips in timeline. */ void temporaryUnplug(QList clipIds, bool hide); /** @brief Returns the current doc's subtitle model. */ - std::shared_ptr getSubtitleModel(); + std::shared_ptr getSubtitleModel(bool enforce = false); KSharedDataCache audioThumbCache; diff --git a/src/timeline2/view/timelinecontroller.cpp b/src/timeline2/view/timelinecontroller.cpp index b5b6a9038..139c40ab5 100644 --- a/src/timeline2/view/timelinecontroller.cpp +++ b/src/timeline2/view/timelinecontroller.cpp @@ -3794,8 +3794,8 @@ void TimelineController::addSubtitle(int startframe) startframe = pCore->getTimelinePosition(); } int endframe = startframe + pCore->getDurationFromString(KdenliveSettings::subtitle_duration()); + auto subtitleModel = pCore->getSubtitleModel(true); int id = TimelineModel::getNextId(); - auto subtitleModel = pCore->getSubtitleModel(); Fun local_undo = [subtitleModel, id, startframe, endframe]() { subtitleModel->removeSubtitle(id); pCore->refreshProjectRange({startframe, endframe}); -- GitLab