mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Track request lifetime in lambda callbacks
This commit is contained in:
parent
0878d87ac7
commit
419ff3bbea
2 changed files with 12 additions and 6 deletions
|
@ -202,7 +202,7 @@ AssetUpload* AssetClient::createUpload(const QByteArray& data) {
|
|||
}
|
||||
|
||||
MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end,
|
||||
ReceivedAssetCallback callback, ProgressCallback progressCallback) {
|
||||
ReceivedAssetCallback callback, ProgressCallback progressCallback) {
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
|
@ -238,8 +238,6 @@ MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffse
|
|||
callback(false, AssetServerError::NoError, QByteArray());
|
||||
return INVALID_MESSAGE_ID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
MessageID AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) {
|
||||
|
|
|
@ -106,9 +106,13 @@ void AssetRequest::start() {
|
|||
int start = 0, end = _info.size;
|
||||
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto that = QPointer<AssetRequest>(this); // Used to track the request's lifetime
|
||||
_assetRequestID = assetClient->getAsset(_hash, start, end,
|
||||
[this, start, end](bool responseReceived, AssetServerError serverError, const QByteArray& data) {
|
||||
|
||||
[this, that, start, end](bool responseReceived, AssetServerError serverError, const QByteArray& data) {
|
||||
if (!that) {
|
||||
// If the request is dead, return
|
||||
return;
|
||||
}
|
||||
_assetRequestID = AssetClient::INVALID_MESSAGE_ID;
|
||||
|
||||
if (!responseReceived) {
|
||||
|
@ -148,7 +152,11 @@ void AssetRequest::start() {
|
|||
|
||||
_state = Finished;
|
||||
emit finished(this);
|
||||
}, [this](qint64 totalReceived, qint64 total) {
|
||||
}, [this, that](qint64 totalReceived, qint64 total) {
|
||||
if (!that) {
|
||||
// If the request is dead, return
|
||||
return;
|
||||
}
|
||||
emit progress(totalReceived, total);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue