From 190144ef6eae94b989c992595d043845242bd8e1 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Wed, 13 Feb 2013 05:32:02 +0000 Subject: Fix for a crash when the Polygonization geometry modifier is used with a small "error" parameter value. The problem was caused by a null pointer reference in CurvePiece::error() resulting from incorrect lengths of subdivided curves calculated in CurvePiece::subdivide(). Problem report by IRIE Shinsuke with a GDB backtrace log, many thanks! --- .../blender/freestyle/intern/stroke/BasicStrokeShaders.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index dd6e6dc317e..73651e7d672 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -955,11 +955,13 @@ public: CurvePiece *subdivide() { StrokeInternal::StrokeVertexIterator it = _begin; - int actualSize = (size > 1) ? size / 2 : 1; - for (int i = 0; i <= actualSize; ++it, ++i); + int ns = size - 1; // number of segments (ns > 1) + int ns1 = ns / 2; + int ns2 = ns - ns1; + for (int i = 0; i < ns1; ++it, ++i); - CurvePiece *second = new CurvePiece(it, _last, size - actualSize + 1); - size = actualSize; + CurvePiece *second = new CurvePiece(it, _last, ns2 + 1); + size = ns1 + 1; _last = it; B = Vec2d((_last)->x(), (_last)->y()); return second; @@ -984,7 +986,7 @@ int PolygonalizationShader::shade(Stroke& stroke) const while (!_pieces.empty()) { piece = _pieces.back(); _pieces.pop_back(); - if (piece->error() > _error) { + if (piece->size > 2 && piece->error() > _error) { CurvePiece *second = piece->subdivide(); _pieces.push_back(second); _pieces.push_back(piece); -- cgit v1.2.3