Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 4 files). Show all
Unified · Split
| @@ -252,16 +252,17 @@ Texture::~Texture() { · 251 unmodified lines | ||
| 252 | 252 | glDeleteTextures(1, &_id); |
| 253 | 253 | } |
| 254 | 254 | |
| 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 | + | |
| 256 | 261 | if (!url.isValid()) { |
| 257 | 262 | return; |
| 258 | 263 | } |
| 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(); | |
| 265 | 266 | |
| 266 | 267 | // default to white/blue |
| 267 | 268 | glBindTexture(GL_TEXTURE_2D, getID()); |
| @@ -279,6 +280,13 @@ void NetworkTexture::imageLoaded(const QImage& image) { · 11 unmodified lines | ||
| 279 | 280 | // nothing by default |
| 280 | 281 | } |
| 281 | 282 | |
| 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 | + | |
| 282 | 290 | void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { |
| 283 | 291 | if (bytesReceived < bytesTotal && !_reply->isFinished()) { |
| 284 | 292 | return; |
| @@ -314,11 +322,22 @@ void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTo · 29 unmodified lines | ||
| 314 | 322 | } |
| 315 | 323 | |
| 316 | 324 | void NetworkTexture::handleReplyError() { |
| 317 | − qDebug() << _reply->errorString() << "\n"; | |
| 325 | + QDebug debug = qDebug() << _reply->errorString(); | |
| 318 | 326 | |
| 319 | 327 | _reply->disconnect(this); |
| 320 | 328 | _reply->deleteLater(); |
| 321 | 329 | _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 | + } | |
| 322 | 341 | } |
| 323 | 342 | |
| 324 | 343 | DilatableNetworkTexture::DilatableNetworkTexture(const QUrl& url, bool normalMap) : |