summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/map/tile_data.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp
index fdec759938..74993ff52a 100644
--- a/src/mbgl/map/tile_data.cpp
+++ b/src/mbgl/map/tile_data.cpp
@@ -20,9 +20,7 @@ TileData::TileData(const TileID& id_, const SourceInfo& source_)
}
TileData::~TileData() {
- if (req) {
- env.cancelRequest(req);
- }
+ cancel();
}
const std::string TileData::toString() const {
@@ -33,28 +31,19 @@ void TileData::request(uv::worker &worker, float pixelRatio, std::function<void(
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
- std::weak_ptr<TileData> weak_tile = shared_from_this();
- req = env.request({ Resource::Kind::Tile, url }, [weak_tile, url, callback, &worker](const Response &res) {
- util::ptr<TileData> tile = weak_tile.lock();
- if (!tile || tile->state == State::obsolete) {
- // noop. Tile is obsolete and we're now just waiting for the refcount
- // to drop to zero for destruction.
+ req = env.request({ Resource::Kind::Tile, url }, [url, callback, &worker, this](const Response &res) {
+ req = nullptr;
+
+ if (res.status != Response::Successful) {
+ Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
return;
}
- // Clear the request object.
- tile->req = nullptr;
-
- if (res.status == Response::Successful) {
- tile->state = State::loaded;
-
- tile->data = res.data;
+ state = State::loaded;
+ data = res.data;
- // Schedule tile parsing in another thread
- tile->reparse(worker, callback);
- } else {
- Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
- }
+ // Schedule tile parsing in another thread
+ reparse(worker, callback);
});
}