fix resource crash

This commit is contained in:
SamGondelman 2019-03-01 15:50:50 -08:00
parent cc9a3e2541
commit 884a64bfa6

View file

@ -353,16 +353,19 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
// We've seen this extra info before // We've seen this extra info before
resource = resourcesWithExtraHashIter.value().lock(); resource = resourcesWithExtraHashIter.value().lock();
} else if (resourcesWithExtraHash.size() > 0.0f) { } 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). auto oldResource = resourcesWithExtraHash.begin().value().lock();
resource = createResourceCopy(resourcesWithExtraHash.begin().value().lock()); if (oldResource) {
resource->setExtra(extra); // 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->setExtraHash(extraHash); resource = createResourceCopy(oldResource);
resource->setSelf(resource); resource->setExtra(extra);
resource->setCache(this); resource->setExtraHash(extraHash);
resource->moveToThread(qApp->thread()); resource->setSelf(resource);
connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); resource->setCache(this);
resourcesWithExtraHash.insert(extraHash, resource); resource->moveToThread(qApp->thread());
resource->ensureLoading(); connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize);
resourcesWithExtraHash.insert(extraHash, resource);
resource->ensureLoading();
}
} }
} }
if (resource) { if (resource) {