From 812515b623be9179e67d97b84b10df587244d38c Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Wed, 4 Jun 2014 14:51:39 +0900 Subject: Freestyle: Fix for a potential infinite loop in stroke resampling by vertex count. Changes were made in Stroke::Resample(int) in C++ to prevent a potential infinite loop caused by an inconsistency between Stroke::_Length and the stroke length computed based on stroke vertices. Such a stroke length inconsistency is usually caused by missing calls of Stroke::UpdateLength() (i.e., API implementation bugs), but also may occur due to scripting errors in user-defined style modules. This commit is meant to help script writters to identify the latter error cases. Now Stroke.resample(int) may raise a runtime error to signal an error condition. --- .../blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source/blender/freestyle/intern/python') diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index 7110eef9036..aa8c90cfd24 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -151,10 +151,16 @@ static PyObject *Stroke_resample(BPy_Stroke *self, PyObject *args, PyObject *kwd float f; if (PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist_1, &i)) { - self->s->Resample(i); + if (self->s->Resample(i) < 0) { + PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex count) failed"); + return NULL; + } } else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &f)) { - self->s->Resample(f); + if (self->s->Resample(f) < 0) { + PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex interval) failed"); + return NULL; + } } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); -- cgit v1.2.3