Skip to content

Commit

Permalink
Don't load FeatureIndex#vtLayers from outside FeatureIndex code.
Browse files Browse the repository at this point in the history
Fixes issue #6555 (a possible crash when calling queryRenderedFeatures after querySourceFeatures)
The actual contents of the regression test are not that important -- before this fix, the test would crash.
  • Loading branch information
ChrisLoer committed Apr 24, 2018
1 parent a56e6c7 commit 21ecc4e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/data/feature_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ class FeatureIndex {
}
}

// Finds non-symbol features in this tile at a particular position.
query(args: QueryParameters, styleLayers: {[string]: StyleLayer}): {[string]: Array<{ featureIndex: number, feature: GeoJSONFeature }>} {
loadVTLayers(): {[string]: VectorTileLayer} {
if (!this.vtLayers) {
this.vtLayers = new vt.VectorTile(new Protobuf(this.rawTileData)).layers;
this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
}
return this.vtLayers;
}

// Finds non-symbol features in this tile at a particular position.
query(args: QueryParameters, styleLayers: {[string]: StyleLayer}): {[string]: Array<{ featureIndex: number, feature: GeoJSONFeature }>} {
this.loadVTLayers();

const params = args.params || {},
pixelsToTileUnits = EXTENT / args.tileSize / args.scale,
Expand Down Expand Up @@ -201,10 +206,7 @@ class FeatureIndex {
filterLayerIDs: Array<string>,
styleLayers: {[string]: StyleLayer}) {
const result = {};
if (!this.vtLayers) {
this.vtLayers = new vt.VectorTile(new Protobuf(this.rawTileData)).layers;
this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
}
this.loadVTLayers();

const filter = featureFilter(filterSpec);

Expand Down
6 changes: 1 addition & 5 deletions src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,7 @@ class Tile {
querySourceFeatures(result: Array<GeoJSONFeature>, params: any) {
if (!this.latestFeatureIndex || !this.latestFeatureIndex.rawTileData) return;

if (!this.latestFeatureIndex.vtLayers) {
this.latestFeatureIndex.vtLayers =
new vt.VectorTile(new Protobuf(this.latestFeatureIndex.rawTileData)).layers;
}
const vtLayers = this.latestFeatureIndex.vtLayers;
const vtLayers = this.latestFeatureIndex.loadVTLayers();

const sourceLayer = params ? params.sourceLayer : '';
const layer = vtLayers._geojsonTileLayer || vtLayers[sourceLayer];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"type": "Feature",
"properties": {}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 8,
"metadata": {
"test": {
"width": 128,
"height": 128,
"operations": [
[
"querySourceFeatures",
[
"source"
]
]
],
"queryGeometry": [
79,
64
],
"queryOptions": {
}
}
},
"zoom": 0,
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"sprite": "local://sprites/sprite",
"sources": {
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "iconlayer",
"type": "symbol",
"source": "source",
"layout": {
"icon-image": "building-12",
"icon-offset": [15, 0]
}
}
]
}

0 comments on commit 21ecc4e

Please sign in to comment.