From 50c46fb9b3d1c6c423c0e6bf90a1bbc2e571c4bd Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Tue, 14 May 2013 22:51:11 +0000 Subject: Further fix for memory leaks in Freestyle Python API components: - StrokeAttribute thickness setter - BezierCurve (used from within BezierCurveShader) - Smoother (used from within SmoothingShader) --- source/blender/freestyle/intern/geometry/Bezier.cpp | 5 +++++ .../blender/freestyle/intern/python/BPy_StrokeAttribute.cpp | 13 ++++++------- .../freestyle/intern/stroke/AdvancedStrokeShaders.cpp | 7 +++++++ .../blender/freestyle/intern/stroke/AdvancedStrokeShaders.h | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/geometry/Bezier.cpp b/source/blender/freestyle/intern/geometry/Bezier.cpp index e69830f3529..b9099df9a68 100644 --- a/source/blender/freestyle/intern/geometry/Bezier.cpp +++ b/source/blender/freestyle/intern/geometry/Bezier.cpp @@ -106,6 +106,11 @@ BezierCurve::BezierCurve(vector& iPoints, double error) BezierCurve::~BezierCurve() { + if (!_Segments.empty()) { + vector::iterator v, vend; + for (v = _Segments.begin(), vend = _Segments.end(); v != vend; ++v) + delete *v; + } if (_currentSegment) delete _currentSegment; } diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index eb175eb7bca..e17f16a2fa7 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -526,13 +526,12 @@ static PyObject *StrokeAttribute_color_get(BPy_StrokeAttribute *self, void *UNUS static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) { - Vec3f *v = Vec3f_ptr_from_PyObject(value); - if (!v) { + float v[3]; + if (!float_array_from_PyObject(value, v, 3)) { PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector"); return -1; } - self->sa->setColor(v->x(), v->y(), v->z()); - delete v; + self->sa->setColor(v[0], v[1], v[2]); return 0; } @@ -551,12 +550,12 @@ static PyObject *StrokeAttribute_thickness_get(BPy_StrokeAttribute *self, void * static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) { - Vec2f *v = Vec2f_ptr_from_PyObject(value); - if (!v) { + float v[2]; + if (!float_array_from_PyObject(value, v, 2)) { PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector"); return -1; } - self->sa->setThickness(v->x(), v->y()); + self->sa->setThickness(v[0], v[1]); return 0; } diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp index 1279d1824fb..2215bd9df02 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp @@ -214,6 +214,13 @@ Smoother::Smoother(Stroke &ioStroke) _safeTest = (_nbVertices > 4); } +Smoother::~Smoother() +{ + delete[] _vertex; + delete[] _curvature; + delete[] _normal; +} + void Smoother::smooth(int nbIteration, real iFactorPoint, real ifactorCurvature, real iFactorCurvatureDifference, real iAnisoPoint, real iAnisoNormal, real iAnisoCurvature, real iCarricatureFactor) { diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h index bd2b28059d8..18472ff2c2a 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h @@ -154,7 +154,7 @@ class LIB_STROKE_EXPORT Smoother public: Smoother(Stroke &ioStroke); - virtual ~Smoother() {} + virtual ~Smoother(); void smooth(int nbIterations, real iFactorPoint, real ifactorCurvature, real iFactorCurvatureDifference, real iAnisoPoint, real iAnisoNormal, real iAnisoCurvature, real icarricatureFactor); -- cgit v1.2.3