diff options
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 18d1b37eb3b..e35076ec7fe 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -115,19 +115,25 @@ static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) self->sv_it->decrement(); } else { - /* if sv_it.isEnd() is true, the iterator can't be incremented. if sv_it.isLast() is true, - * the iterator is currently pointing to the final valid argument. Incrementing it further would - * give a python object that can't be dereferenced. */ - if (self->sv_it->atLast() || self->sv_it->isEnd()) { + /* If sv_it.isEnd() is true, the iterator can't be incremented. */ + if (self->sv_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - /* if at the start of the iterator, only return the object - * and don't increment, to keep for-loops in sync */ - if (self->at_start) + /* If at the start of the iterator, only return the object + * and don't increment, to keep for-loops in sync */ + else if (self->at_start) { self->at_start = false; - else + } + /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element. + * Incrementing it further would lead to a state that the iterator can't be dereferenced. */ + else if (self->sv_it->atLast()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else { self->sv_it->increment(); + } } StrokeVertex *sv = self->sv_it->operator->(); return BPy_StrokeVertex_from_StrokeVertex(*sv); @@ -149,9 +155,9 @@ static PyObject *StrokeVertexIterator_incremented(BPy_StrokeVertexIterator *self PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); return NULL; } - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - copy->increment(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.increment(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_decremented_doc, @@ -168,10 +174,9 @@ static PyObject *StrokeVertexIterator_decremented(BPy_StrokeVertexIterator *self PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); return NULL; } - - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - copy->decrement(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.decrement(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, @@ -185,8 +190,7 @@ PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, static PyObject *StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self) { - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, !self->reversed); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); } static PyMethodDef BPy_StrokeVertexIterator_methods[] = { |