Fix crash on adding first subtitle from subtitle widget

parent 46dd76e4
......@@ -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()) {
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;
}
......
......@@ -238,7 +238,7 @@ public:
/** @brief Temporarily un/plug a list of clips in timeline. */
void temporaryUnplug(QList<int> clipIds, bool hide);
/** @brief Returns the current doc's subtitle model. */
std::shared_ptr<SubtitleModel> getSubtitleModel();
std::shared_ptr<SubtitleModel> getSubtitleModel(bool enforce = false);
KSharedDataCache audioThumbCache;
......
......@@ -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});
......
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