mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 11:10:03 +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) {
|
||||
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() {
|
||||
|
@ -82,12 +93,16 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
|||
int highestIndex = -1;
|
||||
float highestPriority = -FLT_MAX;
|
||||
QSharedPointer<Resource> highestResource;
|
||||
|
||||
for (int i = 0; i < _pendingRequests.size();) {
|
||||
// Clear any freed resources
|
||||
auto resource = _pendingRequests.at(i).lock();
|
||||
if (!resource) {
|
||||
_pendingRequests.removeAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check load priority
|
||||
float priority = resource->getLoadPriority();
|
||||
if (priority >= highestPriority) {
|
||||
highestPriority = priority;
|
||||
|
@ -96,9 +111,11 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (highestIndex >= 0) {
|
||||
_pendingRequests.takeAt(highestIndex);
|
||||
}
|
||||
|
||||
return highestResource;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue