fix resource crash

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

View file

@ -353,8 +353,10 @@ 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) {
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). // 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 = createResourceCopy(oldResource);
resource->setExtra(extra); resource->setExtra(extra);
resource->setExtraHash(extraHash); resource->setExtraHash(extraHash);
resource->setSelf(resource); resource->setSelf(resource);
@ -365,6 +367,7 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
resource->ensureLoading(); resource->ensureLoading();
} }
} }
}
if (resource) { if (resource) {
removeUnusedResource(resource); removeUnusedResource(resource);
} }