From 6b098bfc6a804b465d398b246b1a0ea7145ad131 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 6 Dec 2017 13:51:31 -0800 Subject: [PATCH] Fix aborted baking in oven cli --- assignment-client/src/assets/AssetServer.cpp | 4 ++-- assignment-client/src/assets/BakeAssetTask.cpp | 16 ++++++++++------ assignment-client/src/assets/BakeAssetTask.h | 2 +- libraries/shared/src/SharedUtil.cpp | 12 +++++------- tools/oven/src/BakerCLI.cpp | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index e9cd2cbbd7..98c29b02bb 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -29,11 +29,11 @@ #include #include -#include -#include #include #include #include +#include +#include #include "AssetServerLogging.h" #include "BakeAssetTask.h" diff --git a/assignment-client/src/assets/BakeAssetTask.cpp b/assignment-client/src/assets/BakeAssetTask.cpp index a2fbd5fef4..58983f4660 100644 --- a/assignment-client/src/assets/BakeAssetTask.cpp +++ b/assignment-client/src/assets/BakeAssetTask.cpp @@ -62,16 +62,20 @@ void BakeAssetTask::run() { "-t", extension, }; - auto _ovenProcess = new QProcess(this); + _ovenProcess.reset(new QProcess()); - connect(_ovenProcess, static_cast(&QProcess::finished), + connect(_ovenProcess.get(), static_cast(&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 outputFiles; @@ -111,6 +115,6 @@ void BakeAssetTask::run() { void BakeAssetTask::abort() { if (!_wasAborted.exchange(true)) { - _ovenProcess.terminate(); + _ovenProcess->terminate(); } } diff --git a/assignment-client/src/assets/BakeAssetTask.h b/assignment-client/src/assets/BakeAssetTask.h index 970ea83317..d6c2446df5 100644 --- a/assignment-client/src/assets/BakeAssetTask.h +++ b/assignment-client/src/assets/BakeAssetTask.h @@ -46,7 +46,7 @@ private: AssetPath _assetPath; QString _filePath; QDir _outputDir; - QProcess _ovenProcess { nullptr }; + std::unique_ptr _ovenProcess { nullptr }; std::atomic _wasAborted { false }; std::atomic _didFinish { false }; }; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 7ca915b0d0..2d2ec7c28f 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -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 #include #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 } diff --git a/tools/oven/src/BakerCLI.cpp b/tools/oven/src/BakerCLI.cpp index e28d914e47..eee92d7295 100644 --- a/tools/oven/src/BakerCLI.cpp +++ b/tools/oven/src/BakerCLI.cpp @@ -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