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

Commit 7ac91f5

Browse files
committed
[core] don’t query rendered features until all data is available
1 parent a0da2fb commit 7ac91f5

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

cmake/test-files.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ set(MBGL_TEST_FILES
101101
test/text/quads.test.cpp
102102

103103
# tile
104+
test/tile/annotation_tile.test.cpp
104105
test/tile/geojson_tile.test.cpp
105106
test/tile/geometry_tile_data.test.cpp
106107
test/tile/raster_tile.test.cpp

src/mbgl/annotation/annotation_tile.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ class AnnotationTileLayer : public GeometryTileLayer {
4545
AnnotationTileLayer(std::string);
4646

4747
std::size_t featureCount() const override { return features.size(); }
48-
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override { return std::make_unique<AnnotationTileFeature>(features[i]); }
48+
49+
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override {
50+
return std::make_unique<AnnotationTileFeature>(features.at(i));
51+
}
52+
4953
std::string getName() const override { return name; };
5054

5155
std::vector<AnnotationTileFeature> features;

src/mbgl/tile/geometry_tile.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void GeometryTile::onLayout(LayoutResult result) {
113113
nonSymbolBuckets = std::move(result.nonSymbolBuckets);
114114
featureIndex = std::move(result.featureIndex);
115115
data = std::move(result.tileData);
116+
collisionTile.reset();
116117
observer->onTileChanged(*this);
117118
}
118119

test/tile/annotation_tile.test.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <mbgl/test/util.hpp>
2+
#include <mbgl/test/fake_file_source.hpp>
3+
4+
#include <mbgl/util/default_thread_pool.hpp>
5+
#include <mbgl/util/run_loop.hpp>
6+
#include <mbgl/map/transform.hpp>
7+
#include <mbgl/map/query.hpp>
8+
#include <mbgl/style/style.hpp>
9+
#include <mbgl/style/update_parameters.hpp>
10+
#include <mbgl/map/query.hpp>
11+
#include <mbgl/text/collision_tile.hpp>
12+
#include <mbgl/geometry/feature_index.hpp>
13+
#include <mbgl/annotation/annotation_manager.hpp>
14+
#include <mbgl/annotation/annotation_tile.hpp>
15+
16+
#include <memory>
17+
18+
using namespace mbgl;
19+
20+
class AnnotationTileTest {
21+
public:
22+
FakeFileSource fileSource;
23+
TransformState transformState;
24+
util::RunLoop loop;
25+
ThreadPool threadPool { 1 };
26+
AnnotationManager annotationManager { 1.0 };
27+
style::Style style { fileSource, 1.0 };
28+
29+
style::UpdateParameters updateParameters {
30+
1.0,
31+
MapDebugOptions(),
32+
transformState,
33+
threadPool,
34+
fileSource,
35+
MapMode::Continuous,
36+
annotationManager,
37+
style
38+
};
39+
};
40+
41+
// Don't query stale collision tile
42+
TEST(AnnotationTile, Issue8289) {
43+
AnnotationTileTest test;
44+
AnnotationTile tile(OverscaledTileID(0, 0, 0), test.updateParameters);
45+
46+
auto data = std::make_unique<AnnotationTileData>();
47+
data->layers.emplace("test", AnnotationTileLayer("test"));
48+
data->layers.at("test").features.push_back(AnnotationTileFeature(0, FeatureType::Point, GeometryCollection()));
49+
50+
// Simulate layout and placement of a symbol layer.
51+
tile.onLayout(GeometryTile::LayoutResult {
52+
{},
53+
std::make_unique<FeatureIndex>(),
54+
std::move(data),
55+
0
56+
});
57+
58+
auto collisionTile = std::make_unique<CollisionTile>(PlacementConfig());
59+
60+
IndexedSubfeature subfeature { 0, "", "", 0 };
61+
CollisionFeature feature(GeometryCoordinates(), Anchor(0, 0, 0, 0), -5, 5, -5, 5, 1, 0, style::SymbolPlacementType::Point, subfeature, false);
62+
collisionTile->insertFeature(feature, 0, true);
63+
collisionTile->placeFeature(feature, false, false);
64+
65+
tile.onPlacement(GeometryTile::PlacementResult {
66+
{},
67+
std::move(collisionTile),
68+
0
69+
});
70+
71+
// Simulate a second layout with empty data.
72+
tile.onLayout(GeometryTile::LayoutResult {
73+
{},
74+
std::make_unique<FeatureIndex>(),
75+
std::make_unique<AnnotationTileData>(),
76+
0
77+
});
78+
79+
std::unordered_map<std::string, std::vector<Feature>> result;
80+
GeometryCoordinates queryGeometry {{ Point<int16_t>(0, 0) }};
81+
TransformState transformState;
82+
RenderedQueryOptions options;
83+
84+
tile.queryRenderedFeatures(result, queryGeometry, transformState, options);
85+
86+
EXPECT_TRUE(result.empty());
87+
}
88+

0 commit comments

Comments
 (0)