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

Fix possible crash on profile switch, based on a contribution from Ivan Sudakov.

Related to #1320
parent abb1d7a9
......@@ -416,7 +416,13 @@ std::unique_ptr<Mlt::Repository> &Core::getMltRepository()
std::unique_ptr<ProfileModel> &Core::getCurrentProfile() const
{
return ProfileRepository::get()->getProfile(m_currentProfile);
if (m_projectProfile == nullptr) {
m_projectProfile = std::make_unique<ProfileModel>(m_currentProfile.toStdString().c_str());
m_projectProfile->set_explicit(true);
updateMonitorProfile();
}
return m_projectProfile;
}
Mlt::Profile &Core::getMonitorProfile()
......@@ -426,15 +432,10 @@ Mlt::Profile &Core::getMonitorProfile()
Mlt::Profile *Core::getProjectProfile()
{
if (!m_projectProfile) {
m_projectProfile = std::make_unique<Mlt::Profile>(m_currentProfile.toStdString().c_str());
m_projectProfile->set_explicit(true);
updateMonitorProfile();
}
return m_projectProfile.get();
return &getCurrentProfile()->profile();
}
void Core::updateMonitorProfile()
void Core::updateMonitorProfile() const
{
m_monitorProfile.set_colorspace(m_projectProfile->colorspace());
m_monitorProfile.set_frame_rate(m_projectProfile->frame_rate_num(), m_projectProfile->frame_rate_den());
......@@ -454,28 +455,27 @@ const QString &Core::getCurrentProfilePath() const
bool Core::setCurrentProfile(const QString &profilePath)
{
const auto &profileFromRepository = ProfileRepository::get()->getProfile(profilePath);
if (m_currentProfile == profilePath) {
// no change required, ensure timecode has correct fps
m_timecode.setFormat(getCurrentProfile()->fps());
m_timecode.setFormat(profileFromRepository->fps());
return true;
}
if (ProfileRepository::get()->profileExists(profilePath)) {
m_currentProfile = profilePath;
m_thumbProfile.reset();
if (m_projectProfile) {
m_projectProfile->set_colorspace(getCurrentProfile()->colorspace());
m_projectProfile->set_frame_rate(getCurrentProfile()->frame_rate_num(), getCurrentProfile()->frame_rate_den());
m_projectProfile->set_height(getCurrentProfile()->height());
m_projectProfile->set_progressive(getCurrentProfile()->progressive());
m_projectProfile->set_sample_aspect(getCurrentProfile()->sample_aspect_num(), getCurrentProfile()->sample_aspect_den());
m_projectProfile->set_display_aspect(getCurrentProfile()->display_aspect_num(), getCurrentProfile()->display_aspect_den());
m_projectProfile->set_width(getCurrentProfile()->width());
m_projectProfile->get_profile()->description = qstrdup(getCurrentProfile()->description().toUtf8().constData());
m_projectProfile->set_explicit(true);
updateMonitorProfile();
}
const auto &currentProfile = getCurrentProfile();
currentProfile->profile().set_colorspace(profileFromRepository->colorspace());
currentProfile->profile().set_frame_rate(profileFromRepository->frame_rate_num(), profileFromRepository->frame_rate_den());
currentProfile->profile().set_height(profileFromRepository->height());
currentProfile->profile().set_progressive(profileFromRepository->progressive());
currentProfile->profile().set_sample_aspect(profileFromRepository->sample_aspect_num(), profileFromRepository->sample_aspect_den());
currentProfile->profile().set_display_aspect(profileFromRepository->display_aspect_num(), profileFromRepository->display_aspect_den());
currentProfile->profile().set_width(profileFromRepository->width());
currentProfile->profile().get_profile()->description = qstrdup(profileFromRepository->description().toUtf8().constData());
// inform render widget
m_timecode.setFormat(getCurrentProfile()->fps());
m_timecode.setFormat(profileFromRepository->fps());
profileChanged();
emit m_mainWindow->updateRenderWidgetProfile();
m_monitorManager->resetProfiles();
......
......@@ -309,9 +309,9 @@ private:
Timecode m_timecode;
std::unique_ptr<Mlt::Profile> m_thumbProfile;
/** @brief Mlt profile used in the consumer 's monitors */
Mlt::Profile m_monitorProfile;
mutable Mlt::Profile m_monitorProfile;
/** @brief Mlt profile used to build the project's clips */
std::unique_ptr<Mlt::Profile> m_projectProfile;
mutable std::unique_ptr<ProfileModel> m_projectProfile;
bool m_guiConstructed = false;
/** @brief Check that the profile is valid (width is a multiple of 8 and height a multiple of 2 */
void checkProfileValidity();
......@@ -343,7 +343,7 @@ public slots:
/** @brief Open the proxies test dialog. */
void testProxies();
/** @brief Refresh the monitor profile when project profile changes. */
void updateMonitorProfile();
void updateMonitorProfile() const;
/** @brief Add a new Bin Widget. */
void addBin(const QString &id = QString());
/** @brief Transcode a bin clip video. */
......@@ -376,7 +376,7 @@ signals:
/** @brief Add a time remap effect to clip and show keyframes dialog */
void remapClip(int cid);
/** @brief A monitor property changed, check if we need to reset */
void monitorProfileUpdated();
void monitorProfileUpdated() const;
/** @brief Color theme changed, process refresh */
void updatePalette();
/** @brief Emitted when a clip is resized (to handle clip monitor inserted zones) */
......
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