3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-27 21:55:28 +02:00

Merge pull request from huffman/fix/baking-stuck

Fix/baking stuck
This commit is contained in:
Stephen Birarda 2018-02-23 15:19:29 -07:00 committed by GitHub
commit b18d5db062
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -289,6 +289,7 @@ void AssetServer::aboutToFinish() {
if (pendingRunnable) {
it = _pendingBakes.erase(it);
} else {
qDebug() << "Aborting bake for" << it.key();
it.value()->abort();
++it;
}
@ -1387,6 +1388,8 @@ void AssetServer::handleCompletedBake(QString originalAssetHash, QString origina
}
void AssetServer::handleAbortedBake(QString originalAssetHash, QString assetPath) {
qDebug() << "Aborted bake:" << originalAssetHash;
// for an aborted bake we don't do anything but remove the BakeAssetTask from our pending bakes
_pendingBakes.remove(originalAssetHash);
}

View file

@ -69,8 +69,10 @@ void BakeAssetTask::run() {
_ovenProcess.reset(new QProcess());
QEventLoop loop;
connect(_ovenProcess.get(), static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
this, [this, tempOutputDir](int exitCode, QProcess::ExitStatus exitStatus) {
this, [&loop, this, tempOutputDir](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "Baking process finished: " << exitCode << exitStatus;
if (exitStatus == QProcess::CrashExit) {
@ -108,6 +110,7 @@ void BakeAssetTask::run() {
emit bakeFailed(_assetHash, _assetPath, errors);
}
loop.quit();
});
qDebug() << "Starting oven for " << _assetPath;
@ -117,11 +120,21 @@ void BakeAssetTask::run() {
emit bakeFailed(_assetHash, _assetPath, errors);
return;
}
_ovenProcess->waitForFinished();
_isBaking = true;
loop.exec();
}
void BakeAssetTask::abort() {
if (!_wasAborted.exchange(true)) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "abort");
return;
}
qDebug() << "Aborting BakeAssetTask for" << _assetHash;
if (_ovenProcess->state() != QProcess::NotRunning) {
qDebug() << "Teminating oven process for" << _assetHash;
_wasAborted = true;
_ovenProcess->terminate();
}
}

View file

@ -27,12 +27,14 @@ class BakeAssetTask : public QObject, public QRunnable {
public:
BakeAssetTask(const AssetUtils::AssetHash& assetHash, const AssetUtils::AssetPath& assetPath, const QString& filePath);
// Thread-safe inspection methods
bool isBaking() { return _isBaking.load(); }
bool wasAborted() const { return _wasAborted.load(); }
void run() override;
public slots:
void abort();
bool wasAborted() const { return _wasAborted.load(); }
signals:
void bakeComplete(QString assetHash, QString assetPath, QString tempOutputDir, QVector<QString> outputFiles);