[Bf-blender-cvs] [047c3aa] master: Fix T40020: Freestyle: dashed lines crashes blender.
Tamito Kajiyama
noreply at git.blender.org
Mon May 5 04:35:23 CEST 2014
Commit: 047c3aa728a4bb944616a084805988714b796d52
Author: Tamito Kajiyama
Date: Mon May 5 11:32:43 2014 +0900
https://developer.blender.org/rB047c3aa728a4bb944616a084805988714b796d52
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.
===================================================================
M source/blender/freestyle/intern/stroke/StrokeRep.cpp
===================================================================
diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp
index 4cfdd86..4eee050 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
More information about the Bf-blender-cvs
mailing list