diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-03-05 16:24:10 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-03-05 16:40:07 +0100 |
commit | 1fbaa95b026c2e56c713be689a68e4cddb629308 (patch) | |
tree | 2b699c3763172ec1f2909e140e47532f287ddacd /src/map/tile_data.cpp | |
parent | a3a1b812c8b0638cec2426f87749bf6c4977b459 (diff) | |
download | qtlocation-mapboxgl-1fbaa95b026c2e56c713be689a68e4cddb629308.tar.gz |
fix tile loading
Diffstat (limited to 'src/map/tile_data.cpp')
-rw-r--r-- | src/map/tile_data.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index aadb607854..d62b323dbd 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -34,6 +34,7 @@ TileData::TileData(Tile::ID id, const Style& style) } TileData::~TileData() { + cancel(); } const std::string TileData::toString() const { @@ -48,13 +49,17 @@ void TileData::request() { id.z, id.x, id.y); // Note: Somehow this feels slower than the change to request_http() - std::shared_ptr<TileData> tile = shared_from_this(); + std::weak_ptr<TileData> weak_tile = shared_from_this(); platform::Request *request = platform::request_http(url, [=](platform::Response& res) { - if (res.code == 200 && tile->state != State::obsolete) { + std::shared_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. + } else if (res.code == 200) { tile->state = State::loaded; tile->data.swap(res.body); tile->parse(); - } else if (tile->state != State::obsolete) { + } else { fprintf(stderr, "tile loading failed\n"); } }, []() { @@ -67,8 +72,6 @@ void TileData::cancel() { if (state != State::obsolete) { state = State::obsolete; platform::cancel_request_http(req); - } else { - assert((!"logic error? multiple cancelleations")); } } |