Fix crash on adding first subtitle from subtitle widget

parent 46dd76e4
...@@ -283,10 +283,15 @@ void Core::selectTimelineItem(int id) ...@@ -283,10 +283,15 @@ void Core::selectTimelineItem(int id)
} }
} }
std::shared_ptr<SubtitleModel> Core::getSubtitleModel() std::shared_ptr<SubtitleModel> Core::getSubtitleModel(bool enforce)
{ {
if (m_guiConstructed && m_mainWindow->getCurrentTimeline()->controller()->getModel()) { 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; return nullptr;
} }
......
...@@ -238,7 +238,7 @@ public: ...@@ -238,7 +238,7 @@ public:
/** @brief Temporarily un/plug a list of clips in timeline. */ /** @brief Temporarily un/plug a list of clips in timeline. */
void temporaryUnplug(QList<int> clipIds, bool hide); void temporaryUnplug(QList<int> clipIds, bool hide);
/** @brief Returns the current doc's subtitle model. */ /** @brief Returns the current doc's subtitle model. */
std::shared_ptr<SubtitleModel> getSubtitleModel(); std::shared_ptr<SubtitleModel> getSubtitleModel(bool enforce = false);
KSharedDataCache audioThumbCache; KSharedDataCache audioThumbCache;
......
...@@ -3794,8 +3794,8 @@ void TimelineController::addSubtitle(int startframe) ...@@ -3794,8 +3794,8 @@ void TimelineController::addSubtitle(int startframe)
startframe = pCore->getTimelinePosition(); startframe = pCore->getTimelinePosition();
} }
int endframe = startframe + pCore->getDurationFromString(KdenliveSettings::subtitle_duration()); int endframe = startframe + pCore->getDurationFromString(KdenliveSettings::subtitle_duration());
auto subtitleModel = pCore->getSubtitleModel(true);
int id = TimelineModel::getNextId(); int id = TimelineModel::getNextId();
auto subtitleModel = pCore->getSubtitleModel();
Fun local_undo = [subtitleModel, id, startframe, endframe]() { Fun local_undo = [subtitleModel, id, startframe, endframe]() {
subtitleModel->removeSubtitle(id); subtitleModel->removeSubtitle(id);
pCore->refreshProjectRange({startframe, endframe}); pCore->refreshProjectRange({startframe, endframe});
......
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