From baa162d8626b879b5807912fafa117a61e0aabb5 Mon Sep 17 00:00:00 2001 From: kelteseth Date: Thu, 15 Nov 2018 17:14:13 +0100 Subject: [PATCH] Fix readyRead crash Fix percentage calc --- ScreenPlay/src/create.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ScreenPlay/src/create.cpp b/ScreenPlay/src/create.cpp index 6f1e5db5..997cf783 100644 --- a/ScreenPlay/src/create.cpp +++ b/ScreenPlay/src/create.cpp @@ -277,6 +277,7 @@ bool Create::createWallpaperVideoPreview() #endif proConvertImage.data()->start(); proConvertImage.data()->waitForFinished(-1); + QString tmpErrImg = proConvertImage.data()->readAllStandardError(); if (!tmpErrImg.isEmpty()) { QFile previewImg(m_createWallpaperData.exportPath + "/preview.png"); @@ -325,8 +326,16 @@ bool Create::createWallpaperVideo() proConvertVideo.data()->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe"); qDebug() << "Start converting video"; - connect(proConvertVideo.data(), &QProcess::readyReadStandardOutput, this, [&]() { - QString tmpOut = proConvertVideo.data()->readAllStandardOutput(); + connect(proConvertVideo.data(), &QProcess::readyRead, this, [&]() { + + // Somehow readyRead gets seldom called in the end with an + // not valid QProcess pointer.... + if(proConvertVideo.isNull()) { + qDebug() << "EROR NULL"; + return; + } + + QString tmpOut = proConvertVideo.data()->readAll(); qDebug() << tmpOut << m_createWallpaperData.length; auto tmpList = tmpOut.split(QRegExp("\\s+"), QString::SkipEmptyParts); if (tmpList.length() > 2) { @@ -336,12 +345,13 @@ bool Create::createWallpaperVideo() if (!ok) return; - float progress = currentFrame / m_createWallpaperData.length; + float progress = currentFrame / (m_createWallpaperData.length * m_createWallpaperData.framerate); this->setProgress(progress); } this->processOutput(tmpOut); - }); + }, + Qt::QueuedConnection); // For some reason we only get output if we use execute instead of start....?! #ifdef Q_OS_WIN @@ -349,7 +359,7 @@ bool Create::createWallpaperVideo() #endif proConvertVideo.data()->start(QIODevice::ReadOnly); proConvertVideo.data()->waitForFinished(-1); - disconnect(proConvertVideo.data(), &QProcess::readyReadStandardOutput, 0, 0); + disconnect(proConvertVideo.data(), &QProcess::readyRead, 0, 0); QString out = proConvertVideo.data()->readAllStandardOutput();