summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-08-01 19:31:51 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-08-05 16:13:26 +0300
commit9b34997986698f22e1aa0799896591c17d2ac1a3 (patch)
tree36340d53dadf104ecc78c9fb7424c3e891667da5 /src/mbgl/text
parentd30dc89cf71a9f85620c0845b09ccd497bdd94e6 (diff)
downloadqtlocation-mapboxgl-9b34997986698f22e1aa0799896591c17d2ac1a3.tar.gz
[core] Fix using of uninitialized circle in collision index
In `CollisionIndex::placeLineFeature()` check that previous circle was initialized before asking its center coordinates.
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/collision_index.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp
index 74923312d5..ae8b29c3fb 100644
--- a/src/mbgl/text/collision_index.cpp
+++ b/src/mbgl/text/collision_index.cpp
@@ -163,7 +163,7 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
lastTileDistance = approximateTileDistance(*(firstAndLastGlyph->second.tileDistance), firstAndLastGlyph->second.angle, pixelsToTileUnits, projectedAnchor.second, pitchWithMap);
}
- bool atLeastOneCirclePlaced = false;
+ bool previousCirclePlaced = false;
for (size_t i = 0; i < feature.boxes.size(); i++) {
CollisionBox& circle = feature.boxes[i];
const float boxSignedDistanceFromAnchor = circle.signedDistanceFromAnchor;
@@ -174,6 +174,7 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
// don't need to use this circle because the label
// doesn't extend this far. Either way, mark the circle unused.
circle.used = false;
+ previousCirclePlaced = false;
continue;
}
@@ -181,8 +182,9 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
const float tileUnitRadius = (circle.x2 - circle.x1) / 2;
const float radius = tileUnitRadius * tileToViewport;
- if (atLeastOneCirclePlaced) {
+ if (previousCirclePlaced) {
const CollisionBox& previousCircle = feature.boxes[i - 1];
+ assert(previousCircle.used);
const float dx = projectedPoint.x - previousCircle.px;
const float dy = projectedPoint.y - previousCircle.py;
// The circle edges touch when the distance between their centers is 2x the radius
@@ -203,13 +205,14 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
// use, in which case we want to keep it in place even if it's tightly packed
// with the one before it.
circle.used = false;
+ previousCirclePlaced = false;
continue;
}
}
}
}
- atLeastOneCirclePlaced = true;
+ previousCirclePlaced = true;
circle.px1 = projectedPoint.x - radius;
circle.px2 = projectedPoint.x + radius;
circle.py1 = projectedPoint.y - radius;