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

Commit bb96775

Browse files
pozdnyakovalexshalamov
authored andcommitted
[core] Fix iterators in addRegularDash()
Fix using of invalid iterators.
1 parent 55d5b97 commit bb96775

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/mbgl/geometry/line_atlas.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ void addRoundDash(
5151
const std::vector<DashRange>& ranges, uint32_t yOffset, float stretch, const int n, AlphaImage& image) {
5252
const float halfStretch = stretch * 0.5f;
5353

54+
if (ranges.empty()) return;
55+
5456
for (int y = -n; y <= n; y++) {
5557
int row = yOffset + n + y;
5658
const uint32_t index = image.size.width * row;
5759
uint32_t currIndex = 0;
5860
DashRange range = ranges[currIndex];
5961

60-
for (uint32_t x = 0; x < image.size.width; x++) {
61-
if (x / range.right > 1.0f) {
62-
range = ranges[++currIndex];
62+
for (uint32_t x = 0; x < image.size.width; ++x) {
63+
if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
64+
range = ranges[currIndex];
6365
}
6466

6567
float distLeft = fabsf(x - range.left);
@@ -84,22 +86,24 @@ void addRegularDash(std::vector<DashRange>& ranges, uint32_t yOffset, AlphaImage
8486
// Collapse any zero-length range
8587
for (auto it = ranges.begin(); it != ranges.end();) {
8688
if (it->isZeroLength) {
87-
ranges.erase(it);
89+
it = ranges.erase(it);
8890
} else {
8991
++it;
9092
}
9193
}
9294

93-
if (ranges.size() >= 2) {
95+
if (ranges.empty()) return;
96+
97+
if (ranges.size() > 1) {
9498
// Collapse neighbouring same-type parts into a single part
95-
for (auto curr = ranges.begin(), next = ranges.begin() + 1; curr != ranges.end() && next != ranges.end();) {
99+
for (auto curr = ranges.begin(), next = ranges.begin() + 1; next != ranges.end();) {
96100
if (next->isDash == curr->isDash) {
97101
next->left = curr->left;
98-
ranges.erase(curr);
102+
curr = ranges.erase(curr);
99103
} else {
100104
++curr;
101-
++next;
102105
}
106+
next = curr + 1;
103107
}
104108
}
105109

@@ -115,8 +119,8 @@ void addRegularDash(std::vector<DashRange>& ranges, uint32_t yOffset, AlphaImage
115119
DashRange range = ranges[currIndex];
116120

117121
for (uint32_t x = 0; x < image.size.width; ++x) {
118-
if (x / range.right > 1.0f) {
119-
range = ranges[++currIndex];
122+
if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
123+
range = ranges[currIndex];
120124
}
121125

122126
float distLeft = fabsf(x - range.left);

0 commit comments

Comments
 (0)