History

Merge branch 'master' of git://github.com/worklist/hifi into windows_build

Brad Hefta-Gaub committed 12 years ago

Commit a39c20e2 parents b3e3bcb a8bbe414 files · +61 −18Browse files

Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 4 files). Show all

Unified · Split

interface/src/renderer/TextureCache.cpp+27−8
@@ -252,16 +252,17 @@ Texture::~Texture() { · 251 unmodified lines
252252 glDeleteTextures(1, &_id);
253253 }
254254
255−NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) : _reply(NULL), _averageColor(1.0f, 1.0f, 1.0f, 1.0f) {
255+NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) :
256+ _request(url),
257+ _reply(NULL),
258+ _attempts(0),
259+ _averageColor(1.0f, 1.0f, 1.0f, 1.0f) {
260+
256261 if (!url.isValid()) {
257262 return;
258263 }
259− QNetworkRequest request(url);
260− request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
261− _reply = Application::getInstance()->getNetworkAccessManager()->get(request);
262−
263− connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64)));
264− connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError()));
264+ _request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
265+ makeRequest();
265266
266267 // default to white/blue
267268 glBindTexture(GL_TEXTURE_2D, getID());
@@ -279,6 +280,13 @@ void NetworkTexture::imageLoaded(const QImage& image) { · 11 unmodified lines
279280 // nothing by default
280281 }
281282
283+void NetworkTexture::makeRequest() {
284+ _reply = Application::getInstance()->getNetworkAccessManager()->get(_request);
285+
286+ connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64)));
287+ connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError()));
288+}
289+
282290 void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
283291 if (bytesReceived < bytesTotal && !_reply->isFinished()) {
284292 return;
@@ -314,11 +322,22 @@ void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTo · 29 unmodified lines
314322 }
315323
316324 void NetworkTexture::handleReplyError() {
317− qDebug() << _reply->errorString() << "\n";
325+ QDebug debug = qDebug() << _reply->errorString();
318326
319327 _reply->disconnect(this);
320328 _reply->deleteLater();
321329 _reply = NULL;
330+
331+ // retry with increasing delays
332+ const int MAX_ATTEMPTS = 8;
333+ const int BASE_DELAY_MS = 1000;
334+ if (++_attempts < MAX_ATTEMPTS) {
335+ QTimer::singleShot(BASE_DELAY_MS * (int)pow(2.0, _attempts), this, SLOT(makeRequest()));
336+ debug << " -- retrying...\n";
337+
338+ } else {
339+ debug << "\n";
340+ }
322341 }
323342
324343 DilatableNetworkTexture::DilatableNetworkTexture(const QUrl& url, bool normalMap) :

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t