mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 21:47:09 +02:00
Make BakeAssetTask::abort thread-safe
This commit is contained in:
parent
85bd0442a7
commit
c368c84f59
3 changed files with 22 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue