mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 05:53:29 +02:00
Merge pull request #8824 from huffman/fix/batch-load-crash
Fix race condition in BatchLoader
This commit is contained in:
commit
b43301cd8c
2 changed files with 13 additions and 10 deletions
|
@ -48,6 +48,11 @@ void BatchLoader::start() {
|
|||
if (!self) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Because the ScriptCache may call this callback from differents threads,
|
||||
// we need to make sure this is thread-safe.
|
||||
std::lock_guard<std::mutex> lock(_dataLock);
|
||||
|
||||
if (isURL && success) {
|
||||
_data.insert(url, contents);
|
||||
qCDebug(scriptengine) << "Loaded: " << url;
|
||||
|
@ -55,16 +60,11 @@ void BatchLoader::start() {
|
|||
_data.insert(url, QString());
|
||||
qCDebug(scriptengine) << "Could not load" << url;
|
||||
}
|
||||
checkFinished();
|
||||
|
||||
if (!_finished && _urls.size() == _data.size()) {
|
||||
_finished = true;
|
||||
emit finished(_data);
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
checkFinished();
|
||||
}
|
||||
|
||||
void BatchLoader::checkFinished() {
|
||||
if (!_finished && _urls.size() == _data.size()) {
|
||||
_finished = true;
|
||||
emit finished(_data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
class BatchLoader : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -37,6 +39,7 @@ private:
|
|||
bool _finished;
|
||||
QSet<QUrl> _urls;
|
||||
QMap<QUrl, QString> _data;
|
||||
std::mutex _dataLock;
|
||||
};
|
||||
|
||||
#endif // hifi_BatchLoader_h
|
||||
|
|
Loading…
Reference in a new issue