summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-28 19:28:34 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-28 21:42:03 +0200
commit01c056f46dad0799cc5ab885b84fe0a9f7e1bc99 (patch)
treec469e211bd85c88c1d6939cf28c60ce0adc35b63
parent55d5b976dcea60ad68873fdd4c035630b5912ca9 (diff)
downloadqtlocation-mapboxgl-01c056f46dad0799cc5ab885b84fe0a9f7e1bc99.tar.gz
[core] Fix iterators in addRegularDash()
Fix using of invalid iterators.
-rw-r--r--src/mbgl/geometry/line_atlas.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 3b6d82c46c..656cfbd25c 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -51,15 +51,17 @@ void addRoundDash(
const std::vector<DashRange>& ranges, uint32_t yOffset, float stretch, const int n, AlphaImage& image) {
const float halfStretch = stretch * 0.5f;
+ if (ranges.empty()) return;
+
for (int y = -n; y <= n; y++) {
int row = yOffset + n + y;
const uint32_t index = image.size.width * row;
uint32_t currIndex = 0;
DashRange range = ranges[currIndex];
- for (uint32_t x = 0; x < image.size.width; x++) {
- if (x / range.right > 1.0f) {
- range = ranges[++currIndex];
+ for (uint32_t x = 0; x < image.size.width; ++x) {
+ if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
+ range = ranges[currIndex];
}
float distLeft = fabsf(x - range.left);
@@ -84,22 +86,24 @@ void addRegularDash(std::vector<DashRange>& ranges, uint32_t yOffset, AlphaImage
// Collapse any zero-length range
for (auto it = ranges.begin(); it != ranges.end();) {
if (it->isZeroLength) {
- ranges.erase(it);
+ it = ranges.erase(it);
} else {
++it;
}
}
- if (ranges.size() >= 2) {
+ if (ranges.empty()) return;
+
+ if (ranges.size() > 1) {
// Collapse neighbouring same-type parts into a single part
- for (auto curr = ranges.begin(), next = ranges.begin() + 1; curr != ranges.end() && next != ranges.end();) {
+ for (auto curr = ranges.begin(), next = ranges.begin() + 1; next != ranges.end();) {
if (next->isDash == curr->isDash) {
next->left = curr->left;
- ranges.erase(curr);
+ curr = ranges.erase(curr);
} else {
++curr;
- ++next;
}
+ next = curr + 1;
}
}
@@ -115,8 +119,8 @@ void addRegularDash(std::vector<DashRange>& ranges, uint32_t yOffset, AlphaImage
DashRange range = ranges[currIndex];
for (uint32_t x = 0; x < image.size.width; ++x) {
- if (x / range.right > 1.0f) {
- range = ranges[++currIndex];
+ if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
+ range = ranges[currIndex];
}
float distLeft = fabsf(x - range.left);