Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[CP][core] Fix of incorrect resizing of TileCache #15943

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions next/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ add_library(
${MBGL_ROOT}/test/tile/geometry_tile_data.test.cpp
${MBGL_ROOT}/test/tile/raster_dem_tile.test.cpp
${MBGL_ROOT}/test/tile/raster_tile.test.cpp
${MBGL_ROOT}/test/tile/tile_cache.test.cpp
${MBGL_ROOT}/test/tile/tile_coordinate.test.cpp
${MBGL_ROOT}/test/tile/tile_id.test.cpp
${MBGL_ROOT}/test/tile/vector_tile.test.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/tile/tile_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void TileCache::setSize(size_t size_) {

while (orderedKeys.size() > size) {
auto key = orderedKeys.front();
orderedKeys.pop_front();
orderedKeys.remove(key);
tiles.erase(key);
}

Expand All @@ -21,7 +21,7 @@ void TileCache::add(const OverscaledTileID& key, std::unique_ptr<Tile> tile) {
}

// insert new or query existing tile
if (tiles.emplace(key, std::move(tile)).second) {
if (!tiles.emplace(key, std::move(tile)).second) {
// remove existing tile key
orderedKeys.remove(key);
}
Expand Down
1 change: 1 addition & 0 deletions test/test-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"test/tile/geometry_tile_data.test.cpp",
"test/tile/raster_dem_tile.test.cpp",
"test/tile/raster_tile.test.cpp",
"test/tile/tile_cache.test.cpp",
"test/tile/tile_coordinate.test.cpp",
"test/tile/tile_id.test.cpp",
"test/tile/vector_tile.test.cpp",
Expand Down
87 changes: 87 additions & 0 deletions test/tile/tile_cache.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <mbgl/test/util.hpp>

#include <mbgl/tile/tile_cache.hpp>

#include <mbgl/test/fake_file_source.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
#include <mbgl/tile/vector_tile.hpp>
#include <mbgl/tile/vector_tile_data.hpp>

#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/buckets/symbol_bucket.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/renderer/query.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/text/glyph_manager.hpp>
#include <mbgl/util/run_loop.hpp>

#include <memory>

using namespace mbgl;

class VectorTileTest {
public:
std::shared_ptr<FileSource> fileSource = std::make_shared<FakeFileSource>();
TransformState transformState;
util::RunLoop loop;
style::Style style{*fileSource, 1};
AnnotationManager annotationManager{style};
ImageManager imageManager;
GlyphManager glyphManager;
Tileset tileset{{"https://example.com"}, {0, 22}, "none"};

TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0};
};

class VectorTileMock : public VectorTile {
public:
VectorTileMock(const OverscaledTileID& id,
std::string sourceID,
const TileParameters& parameters,
const Tileset& tileset)
: VectorTile(id, sourceID, parameters, tileset) {
renderable = true;
}
};

TEST(TileCache, Smoke) {
VectorTileTest test;
TileCache cache(1);
OverscaledTileID id(0, 0, 0);
std::unique_ptr<Tile> tile = std::make_unique<VectorTileMock>(id, "source", test.tileParameters, test.tileset);

cache.add(id, std::move(tile));
EXPECT_TRUE(cache.has(id));
cache.clear();
EXPECT_FALSE(cache.has(id));
}

TEST(TileCache, Issue15926) {
VectorTileTest test;
TileCache cache(2);
OverscaledTileID id0(0, 0, 0);
OverscaledTileID id1(1, 0, 0);
std::unique_ptr<Tile> tile1 = std::make_unique<VectorTileMock>(id0, "source", test.tileParameters, test.tileset);
std::unique_ptr<Tile> tile2 = std::make_unique<VectorTileMock>(id0, "source", test.tileParameters, test.tileset);
std::unique_ptr<Tile> tile3 = std::make_unique<VectorTileMock>(id1, "source", test.tileParameters, test.tileset);

cache.add(id0, std::move(tile1));
EXPECT_TRUE(cache.has(id0));
cache.add(id0, std::move(tile2));
cache.setSize(1);
cache.add(id1, std::move(tile3));
EXPECT_FALSE(cache.has(id0));
EXPECT_TRUE(cache.has(id1));
}