Commit e76f9b9c authored by hengli's avatar hengli

Fixed image cache bug: when a cache is full, a new image replaces the first...

Fixed image cache bug: when a cache is full, a new image replaces the first cached image instead of the oldest cached image.
parent eaaa3eb4
...@@ -33,11 +33,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -33,11 +33,8 @@ This file is part of the QGROUNDCONTROL project
#include <cmath> #include <cmath>
//#include <GL/gl.h>
//#include <GL/glu.h>
static const float KEY_ROTATE_AMOUNT = 5.0f; static const float KEY_ROTATE_AMOUNT = 5.0f;
static const float KEY_MOVE_AMOUNT = 10.0f; static const float KEY_MOVE_AMOUNT = 5.0f;
static const float KEY_ZOOM_AMOUNT = 5.0f; static const float KEY_ZOOM_AMOUNT = 5.0f;
Q3DWidget::Q3DWidget(QWidget* parent) Q3DWidget::Q3DWidget(QWidget* parent)
......
...@@ -64,8 +64,6 @@ QMap3DWidget::QMap3DWidget(QWidget* parent) ...@@ -64,8 +64,6 @@ QMap3DWidget::QMap3DWidget(QWidget* parent)
buildLayout(); buildLayout();
//font.reset(new FTTextureFont("images/Vera.ttf"));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*))); this, SLOT(setActiveUAS(UASInterface*)));
} }
......
...@@ -54,66 +54,68 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize) ...@@ -54,66 +54,68 @@ WebImageCache::WebImageCache(QObject* parent, uint32_t _cacheSize)
QPair<WebImagePtr, int32_t> QPair<WebImagePtr, int32_t>
WebImageCache::lookup(const QString& url) WebImageCache::lookup(const QString& url)
{ {
QPair<WebImagePtr, int32_t> p; QPair<WebImagePtr, int32_t> cacheEntry;
for (int32_t i = 0; i < webImages.size(); ++i) for (int32_t i = 0; i < webImages.size(); ++i)
{ {
if (webImages[i]->getState() != WebImage::UNINITIALIZED && if (webImages[i]->getState() != WebImage::UNINITIALIZED &&
webImages[i]->getSourceURL() == url) webImages[i]->getSourceURL() == url)
{ {
p.first = webImages[i]; cacheEntry.first = webImages[i];
p.second = i; cacheEntry.second = i;
break; break;
} }
} }
if (p.first.isNull()) if (cacheEntry.first.isNull())
{ {
for (int32_t i = 0; i < webImages.size(); ++i) for (int32_t i = 0; i < webImages.size(); ++i)
{ {
// get uninitialized image // get uninitialized image
if (webImages[i]->getState() == WebImage::UNINITIALIZED) if (webImages[i]->getState() == WebImage::UNINITIALIZED)
{ {
p.first = webImages[i]; cacheEntry.first = webImages[i];
p.second = i; cacheEntry.second = i;
break; break;
} }
// get oldest image // get oldest image
else if (webImages[i]->getState() == WebImage::READY && else if (webImages[i]->getState() == WebImage::READY &&
(p.first.isNull() || (cacheEntry.first.isNull() ||
p.first->getLastReference() < p.first->getLastReference())) webImages[i]->getLastReference() <
cacheEntry.first->getLastReference()))
{ {
p.first = webImages[i]; cacheEntry.first = webImages[i];
p.second = i; cacheEntry.second = i;
} }
} }
if (p.first.isNull()) if (cacheEntry.first.isNull())
{ {
return qMakePair(WebImagePtr(), -1); return qMakePair(WebImagePtr(), -1);
} }
else else
{ {
if (p.first->getState() == WebImage::READY) if (cacheEntry.first->getState() == WebImage::READY)
{ {
p.first->clear(); cacheEntry.first->clear();
} }
p.first->setSourceURL(url); cacheEntry.first->setSourceURL(url);
p.first->setLastReference(currentReference); cacheEntry.first->setLastReference(currentReference);
++currentReference; ++currentReference;
p.first->setState(WebImage::REQUESTED); cacheEntry.first->setState(WebImage::REQUESTED);
networkManager->get(QNetworkRequest(QUrl(url))); networkManager->get(QNetworkRequest(QUrl(url)));
return p; return cacheEntry;
} }
} }
else else
{ {
if (p.first->getState() == WebImage::READY) if (cacheEntry.first->getState() == WebImage::READY)
{ {
p.first->setLastReference(currentReference); cacheEntry.first->setLastReference(currentReference);
++currentReference; ++currentReference;
return p; return cacheEntry;
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment