Fix aborted baking in oven cli

This commit is contained in:
Ryan Huffman 2017-12-06 13:51:31 -08:00
parent cb9a30413d
commit 6b098bfc6a
5 changed files with 20 additions and 18 deletions

View file

@ -29,11 +29,11 @@
#include <QtCore/QUrlQuery>
#include <ClientServerUtils.h>
#include <FBXBaker.h>
#include <JSBaker.h>
#include <NodeType.h>
#include <SharedUtil.h>
#include <PathUtils.h>
#include <image/Image.h>
#include <TextureBaker.h>
#include "AssetServerLogging.h"
#include "BakeAssetTask.h"

View file

@ -62,16 +62,20 @@ void BakeAssetTask::run() {
"-t", extension,
};
auto _ovenProcess = new QProcess(this);
_ovenProcess.reset(new QProcess());
connect(_ovenProcess, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
connect(_ovenProcess.get(), static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
this, [this, tempOutputDir](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "Baking process finished: " << exitCode << exitStatus;
if (exitStatus == QProcess::CrashExit) {
_didFinish.store(true);
QString errors = "Fatal error occurred while baking";
emit bakeFailed(_assetHash, _assetPath, errors);
if (_wasAborted) {
emit bakeAborted(_assetHash, _assetPath);
} else {
_didFinish.store(true);
QString errors = "Fatal error occurred while baking";
emit bakeFailed(_assetHash, _assetPath, errors);
}
} else if (exitCode == OVEN_STATUS_CODE_SUCCESS) {
auto files = _outputDir.entryInfoList(QDir::Files);
QVector<QString> outputFiles;
@ -111,6 +115,6 @@ void BakeAssetTask::run() {
void BakeAssetTask::abort() {
if (!_wasAborted.exchange(true)) {
_ovenProcess.terminate();
_ovenProcess->terminate();
}
}

View file

@ -46,7 +46,7 @@ private:
AssetPath _assetPath;
QString _filePath;
QDir _outputDir;
QProcess _ovenProcess { nullptr };
std::unique_ptr<QProcess> _ovenProcess { nullptr };
std::atomic<bool> _wasAborted { false };
std::atomic<bool> _didFinish { false };
};

View file

@ -45,7 +45,7 @@ extern "C" FILE * __cdecl __iob_func(void) {
#endif
#if defined(Q_OS_LINUX) || defined(__APPLE__)
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
#include <signal.h>
#include <cerrno>
#endif
@ -1088,19 +1088,17 @@ bool processIsRunning(int64_t pid) {
#ifdef Q_OS_WIN
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (process) {
DWORD exitCodeOut;
if (GetExitCodeProcess(process, &exitCodeOut) != 0) {
return exitCodeOut == STILL_ACTIVE;
DWORD exitCode;
if (GetExitCodeProcess(process, &exitCode) != 0) {
return exitCode == STILL_ACTIVE;
}
}
return false;
#elif defined(Q_OS_LINUX) || defined(__APPLE__)
#else
if (kill(pid, 0) == -1) {
return errno != ESRCH;
}
return true;
#else
static_assert(false);
#endif
}

View file

@ -30,7 +30,7 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString& outputPath, const QString&
inputUrl.setScheme("file");
}
qDebug() << "Type: " << type;
qDebug() << "Baking file type: " << type;
static const QString MODEL_EXTENSION { "fbx" };
@ -57,7 +57,7 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString& outputPath, const QString&
_baker->moveToThread(qApp->getNextWorkerThread());
} else {
qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl;
QApplication::exit(1);
QApplication::exit(OVEN_STATUS_CODE_FAIL);
}
// invoke the bake method on the baker thread