From f04f42df8f0fb64a5fbd594b27229a732d8cac4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 6 Mar 2014 13:24:14 +0100 Subject: [PATCH] load new tile if it's marked as obsolete --- src/map/map.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index bf64d65bd..852732d37 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -266,11 +266,19 @@ TileData::State Map::addTile(const Tile::ID& id) { auto it = std::find_if(tile_data.begin(), tile_data.end(), [&normalized_id](const std::weak_ptr& tile_data) { return !tile_data.expired() && tile_data.lock()->id == normalized_id; }); - if (it != tile_data.end() && !it->expired()) { - // There is already a tile data object and it's not yet expired, so we're - // going to reuse it. + + if (it != tile_data.end()) { + // Create a shared_ptr handle. Note that this might be empty! new_tile.data = it->lock(); - } else { + } + + if (new_tile.data && new_tile.data->state == TileData::State::obsolete) { + // Do not consider the tile if it's already obsolete. + new_tile.data.reset(); + } + + if (!new_tile.data) { + // If we don't find working tile data, we're just going to load it. new_tile.data = std::make_shared(normalized_id, style); new_tile.data->request(); tile_data.push_front(new_tile.data);