mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 01:36:26 +02:00
Clear freed loading resources
This commit is contained in:
parent
d2426f30c6
commit
0d06d8ea93
1 changed files with 18 additions and 1 deletions
|
@ -73,7 +73,18 @@ QList<QSharedPointer<Resource>> ResourceCacheSharedItems::getLoadingRequests() {
|
||||||
|
|
||||||
void ResourceCacheSharedItems::removeRequest(QWeakPointer<Resource> resource) {
|
void ResourceCacheSharedItems::removeRequest(QWeakPointer<Resource> resource) {
|
||||||
Lock lock(_mutex);
|
Lock lock(_mutex);
|
||||||
_loadingRequests.removeAll(resource);
|
// resource can only be removed if it still has a ref-count, as
|
||||||
|
// QWeakPointer has no operator== implementation for two weak ptrs, so
|
||||||
|
// manually loop in case resource has been freed.
|
||||||
|
for (int i = 0; i < _loadingRequests.size();) {
|
||||||
|
auto request = _loadingRequests.at(i);
|
||||||
|
// Clear our resource and any freed resources
|
||||||
|
if (!request || request.data() == resource.data()) {
|
||||||
|
_loadingRequests.removeAt(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
||||||
|
@ -82,12 +93,16 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
||||||
int highestIndex = -1;
|
int highestIndex = -1;
|
||||||
float highestPriority = -FLT_MAX;
|
float highestPriority = -FLT_MAX;
|
||||||
QSharedPointer<Resource> highestResource;
|
QSharedPointer<Resource> highestResource;
|
||||||
|
|
||||||
for (int i = 0; i < _pendingRequests.size();) {
|
for (int i = 0; i < _pendingRequests.size();) {
|
||||||
|
// Clear any freed resources
|
||||||
auto resource = _pendingRequests.at(i).lock();
|
auto resource = _pendingRequests.at(i).lock();
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
_pendingRequests.removeAt(i);
|
_pendingRequests.removeAt(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check load priority
|
||||||
float priority = resource->getLoadPriority();
|
float priority = resource->getLoadPriority();
|
||||||
if (priority >= highestPriority) {
|
if (priority >= highestPriority) {
|
||||||
highestPriority = priority;
|
highestPriority = priority;
|
||||||
|
@ -96,9 +111,11 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highestIndex >= 0) {
|
if (highestIndex >= 0) {
|
||||||
_pendingRequests.takeAt(highestIndex);
|
_pendingRequests.takeAt(highestIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return highestResource;
|
return highestResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue