From 3f5d02ee6509e2fe0abb9bb9aa34979a3bad932c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 7 Jan 2016 12:38:07 +0100 Subject: [core] use stale raster tiles --- src/mbgl/map/raster_tile_data.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp index a462b86bec..19baa26e55 100644 --- a/src/mbgl/map/raster_tile_data.cpp +++ b/src/mbgl/map/raster_tile_data.cpp @@ -26,23 +26,25 @@ void RasterTileData::request(const std::string& url, FileSource* fs = util::ThreadContext::getFileSource(); req = fs->request({ Resource::Kind::Tile, url }, [url, callback, this](Response res) { - if (res.stale) { - // Only handle fresh responses. - return; - } - req = nullptr; - if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound) { + // This is a 404 response. We're treating these as empty tiles. + workRequest.reset(); state = State::parsed; + bucket.reset(); } else { + // This is a different error, e.g. a connection or server error. error = std::make_exception_ptr(std::runtime_error(res.error->message)); - state = State::obsolete; } callback(); return; } + if (res.notModified) { + // We got the same data again. Abort early. + return; + } + if (state == State::loading) { // Only overwrite the state when we didn't have a previous tile. state = State::loaded; @@ -51,6 +53,7 @@ void RasterTileData::request(const std::string& url, modified = res.modified; expires = res.expires; + workRequest.reset(); workRequest = worker.parseRasterTile(std::make_unique(texturePool), res.data, [this, callback] (RasterTileParseResult result) { workRequest.reset(); if (state != State::loaded) { @@ -63,6 +66,7 @@ void RasterTileData::request(const std::string& url, } else { error = result.get(); state = State::obsolete; + bucket.reset(); } callback(); -- cgit v1.2.1