Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-05-05 06:32:43 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-05-05 06:33:53 +0400
commit047c3aa728a4bb944616a084805988714b796d52 (patch)
tree84ce936e593cd4b1ffaec24dee325c34c80236d2 /source/blender/freestyle/intern/stroke
parent620901426c3ad52585b933f83c4a02cfde67130a (diff)
Fix T40020: Freestyle: dashed lines crashes blender.
The crash was due to an out-of-range vertex index reference that occured while computing texture coordinates of strokes with tips.
Diffstat (limited to 'source/blender/freestyle/intern/stroke')
-rw-r--r--source/blender/freestyle/intern/stroke/StrokeRep.cpp117
1 files changed, 61 insertions, 56 deletions
diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp
index 4cfdd860d20..4eee050c689 100644
--- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp
+++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp
@@ -552,35 +552,37 @@ void Strip::computeTexCoordWithTips (const vector<StrokeVertex*>& iStrokeVertice
uPrev = u;
}
- // first transition vertex
- if (fabs(u - uPrev) > ZERO)
- t = (0.25 - uPrev) / (u - uPrev);
- else
- t = 0;
- for (int k = 0; k < 2; k++) {
- tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d());
- tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord());
- // v coord is 0.5 for tvRep[0], 1.0 for tvRep[1]
- tvRep[k]->setTexCoord(Vec2r(0.25, 0.5 * (k + 1)), true);
- tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB()));
- tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha());
- i++;
- }
- for (int k = 0; k < 2; k++) {
- currentSV = _vertices.insert(currentSV, tvRep[k]);
- ++currentSV;
- }
+ if (i >= 2) {
+ // first transition vertex
+ if (fabs(u - uPrev) > ZERO)
+ t = (0.25 - uPrev) / (u - uPrev);
+ else
+ t = 0;
+ for (int k = 0; k < 2; k++) {
+ tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d());
+ tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord());
+ // v coord is 0.5 for tvRep[0], 1.0 for tvRep[1]
+ tvRep[k]->setTexCoord(Vec2r(0.25, 0.5 * (k + 1)), true);
+ tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB()));
+ tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha());
+ i++;
+ }
+ for (int k = 0; k < 2; k++) {
+ currentSV = _vertices.insert(currentSV, tvRep[k]);
+ ++currentSV;
+ }
- // copy the vertices with different texture coordinates
- for (int k = 0; k < 2; k++) {
- tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2]));
- // v coord is 0.0 for tvRep[0], 0.5 for tvRep[1]
- tvRep[k]->setTexCoord(Vec2r(0.0, 0.5 * k), true); // FIXED u coord
- i++;
- }
- for (int k = 0; k < 2; k++) {
- currentSV = _vertices.insert(currentSV, tvRep[k]);
- ++currentSV;
+ // copy the vertices with different texture coordinates
+ for (int k = 0; k < 2; k++) {
+ tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2]));
+ // v coord is 0.0 for tvRep[0], 0.5 for tvRep[1]
+ tvRep[k]->setTexCoord(Vec2r(0.0, 0.5 * k), true); // FIXED u coord
+ i++;
+ }
+ for (int k = 0; k < 2; k++) {
+ currentSV = _vertices.insert(currentSV, tvRep[k]);
+ ++currentSV;
+ }
}
}
uPrev = 0;
@@ -604,36 +606,39 @@ void Strip::computeTexCoordWithTips (const vector<StrokeVertex*>& iStrokeVertice
uPrev = u;
}
+
if (tipEnd) {
- // second transition vertex
- if (fabs(u - uPrev) > ZERO)
- t = (float(tiles) - uPrev) / (u - uPrev);
- else
- t = 0;
- for (int k = 0; k < 2; k++) {
- tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d());
- tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord());
- // v coord is 0.0 for tvRep[0], 0.5 for tvRep[1]
- tvRep[k]->setTexCoord(Vec2r((real)tiles, 0.5 * k), true); // FIXED u coord
- tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB()));
- tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha());
- i++;
- }
- for (int k = 0; k < 2; k++) {
- currentSV = _vertices.insert(currentSV, tvRep[k]);
- ++currentSV;
- }
+ if (i >= 2) {
+ // second transition vertex
+ if (fabs(u - uPrev) > ZERO)
+ t = (float(tiles) - uPrev) / (u - uPrev);
+ else
+ t = 0;
+ for (int k = 0; k < 2; k++) {
+ tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d());
+ tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord());
+ // v coord is 0.0 for tvRep[0], 0.5 for tvRep[1]
+ tvRep[k]->setTexCoord(Vec2r((real)tiles, 0.5 * k), true); // FIXED u coord
+ tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB()));
+ tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha());
+ i++;
+ }
+ for (int k = 0; k < 2; k++) {
+ currentSV = _vertices.insert(currentSV, tvRep[k]);
+ ++currentSV;
+ }
- // copy the vertices with different texture coordinates
- for (int k = 0; k < 2; k++) {
- tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2]));
- // v coord is 0.5 for tvRep[0], 1.0 for tvRep[1]
- tvRep[k]->setTexCoord(Vec2r(0.75, 0.5 * (k + 1)), true);
- i++;
- }
- for (int k = 0; k < 2; k++) {
- currentSV = _vertices.insert(currentSV, tvRep[k]);
- ++currentSV;
+ // copy the vertices with different texture coordinates
+ for (int k = 0; k < 2; k++) {
+ tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2]));
+ // v coord is 0.5 for tvRep[0], 1.0 for tvRep[1]
+ tvRep[k]->setTexCoord(Vec2r(0.75, 0.5 * (k + 1)), true);
+ i++;
+ }
+ for (int k = 0; k < 2; k++) {
+ currentSV = _vertices.insert(currentSV, tvRep[k]);
+ ++currentSV;
+ }
}
// end tip