From b102b3477ae5a347a11eacacc8a526d95dfb0205 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Fri, 26 Feb 2021 20:04:53 +0100 Subject: [PATCH] Set resource total size to content size when using a qrc:// resource When a Resource is requested from qrc://, the Resource::handleDownloadProgress event is never called, and therefore _bytesTotal remains at zero. This confuses ResourceCache later, which has a sanity check that doesn't pass when resources are retrieved, yet no data accumulates. Fixes #1065 --- libraries/networking/src/ResourceCache.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 4ba456d859..54297415c0 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -794,8 +794,6 @@ void Resource::handleReplyFinished() { { "size_mb", _bytesTotal / 1000000.0 } }); - setSize(_bytesTotal); - // Make sure we keep the Resource alive here auto self = _self.lock(); ResourceCache::requestCompleted(_self); @@ -809,6 +807,14 @@ void Resource::handleReplyFinished() { } auto data = _request->getData(); + if (_request->getUrl().scheme() == "qrc") { + // For resources under qrc://, there's no actual download being done, so + // handleDownloadProgress never gets called. We get the full length here + // at the end. + _bytesTotal = data.length(); + } + + setSize(_bytesTotal); emit loaded(data); downloadFinished(data); } else {