From 884a64bfa6633a9c2029577e2582f9773fd3f99e Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 1 Mar 2019 15:50:50 -0800 Subject: [PATCH] fix resource crash --- libraries/networking/src/ResourceCache.cpp | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 7345081380..d5abb27a27 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -353,16 +353,19 @@ QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& // We've seen this extra info before resource = resourcesWithExtraHashIter.value().lock(); } else if (resourcesWithExtraHash.size() > 0.0f) { - // We haven't seen this extra info before, but we've already downloaded the resource. We need a new copy of this object (with any old hash). - resource = createResourceCopy(resourcesWithExtraHash.begin().value().lock()); - resource->setExtra(extra); - resource->setExtraHash(extraHash); - resource->setSelf(resource); - resource->setCache(this); - resource->moveToThread(qApp->thread()); - connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); - resourcesWithExtraHash.insert(extraHash, resource); - resource->ensureLoading(); + auto oldResource = resourcesWithExtraHash.begin().value().lock(); + if (oldResource) { + // We haven't seen this extra info before, but we've already downloaded the resource. We need a new copy of this object (with any old hash). + resource = createResourceCopy(oldResource); + resource->setExtra(extra); + resource->setExtraHash(extraHash); + resource->setSelf(resource); + resource->setCache(this); + resource->moveToThread(qApp->thread()); + connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); + resourcesWithExtraHash.insert(extraHash, resource); + resource->ensureLoading(); + } } } if (resource) {