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

Fix timeline preview crash. Since a QCoreApp was created by kdenlive_render,...

Fix timeline preview crash. Since a QCoreApp was created by kdenlive_render, MLT did not create its own QApplication, leading to linking crashes
parent ceb8d38d
Pipeline #3445 failed with stage
in 2 minutes and 16 seconds
......@@ -14,7 +14,7 @@ set(kdenlive_render_SRCS
add_executable(kdenlive_render ${kdenlive_render_SRCS})
ecm_mark_nongui_executable(kdenlive_render)
target_link_libraries(kdenlive_render Qt5::Core Qt5::DBus Qt5::Xml
target_link_libraries(kdenlive_render Qt5::Core Qt5::Widgets Qt5::DBus Qt5::Xml
${MLT_LIBRARIES}
${MLTPP_LIBRARIES})
......
......@@ -20,7 +20,7 @@
#include "framework/mlt_version.h"
#include "mlt++/Mlt.h"
#include "renderjob.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QDomDocument>
......@@ -32,7 +32,7 @@
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QApplication app(argc, argv);
QStringList args = app.arguments();
QStringList preargs;
QString locale;
......@@ -76,6 +76,10 @@ int main(int argc, char **argv)
if (!prod.is_valid()) {
fprintf(stderr, "INVALID playlist: %s \n", playlist.toUtf8().constData());
}
profile.from_producer(prod);
profile.set_explicit(1);
const char *localename = prod.get_lcnumeric();
QLocale::setDefault(QLocale(localename));
for (const QString &frame : chunks) {
fprintf(stderr, "START:%d \n", frame.toInt());
QString fileName = QStringLiteral("%1.%2").arg(frame).arg(extension);
......@@ -92,6 +96,9 @@ int main(int argc, char **argv)
cons->set(param.section(QLatin1Char('='), 0, 0).toUtf8().constData(), param.section(QLatin1Char('='), 1).toUtf8().constData());
}
}
if (!cons->is_valid()) {
fprintf(stderr, " = = = INVALID CONSUMER\n\n");
}
cons->set("terminate_on_pause", 1);
cons->connect(*playlst);
playlst.reset();
......
......@@ -44,6 +44,8 @@ PreviewManager::PreviewManager(TimelineController *controller, Mlt::Tractor *tra
{
m_previewGatherTimer.setSingleShot(true);
m_previewGatherTimer.setInterval(200);
QObject::connect(&m_previewProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &PreviewManager::processEnded);
// Find path for Kdenlive renderer
#ifdef Q_OS_WIN
......@@ -473,12 +475,17 @@ void PreviewManager::abortRendering()
qDebug() << "/// ABORTING RENDEIGN 1\nRRRRRRRRRR";
emit abortPreview();
m_previewProcess.waitForFinished();
if (m_previewProcess.state() != QProcess::NotRunning) {
m_previewProcess.kill();
m_previewProcess.waitForFinished();
}
// Re-init time estimation
emit previewRender(-1, QString(), 1000);
}
void PreviewManager::startPreviewRender()
{
QMutexLocker lock(&m_previewMutex);
if (m_renderedChunks.isEmpty() && m_dirtyChunks.isEmpty()) {
m_controller->addPreviewRange(true);
}
......@@ -525,11 +532,8 @@ void PreviewManager::doPreviewRender(const QString &scene)
if (m_dirtyChunks.isEmpty()) {
return;
}
Q_ASSERT(m_previewProcess.state() == QProcess::NotRunning);
if (m_previewProcess.state() != QProcess::NotRunning) {
m_previewProcess.kill();
m_previewProcess.waitForFinished();
}
QStringList chunks;
for (QVariant &frame : m_dirtyChunks) {
chunks << frame.toString();
......@@ -547,30 +551,33 @@ void PreviewManager::doPreviewRender(const QString &scene)
m_consumerParams.join(QLatin1Char(' '))};
qDebug() << " - - -STARTING PREVIEW JOBS: " << args;
pCore->currentDoc()->previewProgress(0);
QObject::connect(&m_previewProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this, scene](int, QProcess::ExitStatus status) {
qDebug() << "// PROCESS IS FINISHED!!!";
QFile::remove(scene);
if (status == QProcess::QProcess::CrashExit) {
qDebug() << "// PROCESS IS CRASHED!!!!!!";
pCore->currentDoc()->previewProgress(-1);
if (workingPreview >= 0) {
const QString fileName = QStringLiteral("%1.%2").arg(workingPreview).arg(m_extension);
if (m_cacheDir.exists(fileName)) {
m_cacheDir.remove(fileName);
}
}
} else {
pCore->currentDoc()->previewProgress(1000);
}
workingPreview = -1;
m_controller->workingPreviewChanged();
});
m_previewProcess.start(m_renderer, args);
if (m_previewProcess.waitForStarted()) {
qDebug() << " - - -STARTING PREVIEW JOBS . . . STARTED";
}
}
void PreviewManager::processEnded(int, QProcess::ExitStatus status)
{
qDebug() << "// PROCESS IS FINISHED!!!";
const QString sceneList = m_cacheDir.absoluteFilePath(QStringLiteral("preview.mlt"));
QFile::remove(sceneList);
if (status == QProcess::QProcess::CrashExit) {
qDebug() << "// PROCESS CRASHED!!!!!!";
pCore->currentDoc()->previewProgress(-1);
if (workingPreview >= 0) {
const QString fileName = QStringLiteral("%1.%2").arg(workingPreview).arg(m_extension);
if (m_cacheDir.exists(fileName)) {
m_cacheDir.remove(fileName);
}
}
} else {
pCore->currentDoc()->previewProgress(1000);
}
workingPreview = -1;
m_controller->workingPreviewChanged();
}
void PreviewManager::slotProcessDirtyChunks()
{
if (m_dirtyChunks.isEmpty()) {
......
......@@ -139,6 +139,7 @@ private slots:
void slotProcessDirtyChunks();
/** @brief: Process preview rendering output. */
void receivedStderr();
void processEnded(int, QProcess::ExitStatus status);
public slots:
/** @brief: Prepare and start rendering. */
......
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