Fix for freestyle iterators with for loops #38213

Closed
opened 2014-01-14 17:34:58 +01:00 by Folkert de Vries · 8 comments

Hello,

As I mentioned some time ago there is a problem with using freestyle iterators in for loops. briefly the problem is that the object returned by next(it), which is implicitly called by a for loop, did not match the it.object: the two were out of sync. an example:

it2 = iter(stroke)
for svert in it2:
  - this will currently crash on the final iteration
  - since it2.object then doesn't exist. 
    print(it2, svert, it2.object)

To solve this problem, the iterator and the next() method have to be brought back into sync. To achieve this I added an attribute to BPy_StrokeVertexIterator, "at_start", that tells the next() whether to increment. this attribute is false on default, so the first call to next() won't increment the iterator, thus getting the for loop and the iterator back into sync.

I've implemented this for StrokeVertexIterators only for now, to check whether this change is allowed and if there are any possible problems I've overlooked.

one further point: I've changed the reversed attribute to be a bool (instead of int), but it seems this attribute is not used anywhere. removing it would make iternext() quite a bit shorter.

patch:
freestyle_iterator_fix.diff

Hello, As I mentioned some time ago there is a problem with using freestyle iterators in for loops. briefly the problem is that the object returned by next(it), which is implicitly called by a for loop, did not match the it.object: the two were out of sync. an example: ``` it2 = iter(stroke) for svert in it2: ``` - this will currently crash on the final iteration - since it2.object then doesn't exist. ``` print(it2, svert, it2.object) ``` To solve this problem, the iterator and the next() method have to be brought back into sync. To achieve this I added an attribute to BPy_StrokeVertexIterator, "at_start", that tells the next() whether to increment. this attribute is false on default, so the first call to next() won't increment the iterator, thus getting the for loop and the iterator back into sync. I've implemented this for StrokeVertexIterators only for now, to check whether this change is allowed and if there are any possible problems I've overlooked. one further point: I've changed the reversed attribute to be a bool (instead of int), but it seems this attribute is not used anywhere. removing it would make iternext() quite a bit shorter. patch: [freestyle_iterator_fix.diff](https://archive.blender.org/developer/F68315/freestyle_iterator_fix.diff)
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Tamito Kajiyama was assigned by Folkert de Vries 2014-01-14 17:34:58 +01:00
Author
Member

Added subscriber: @flokkievids

Added subscriber: @flokkievids
Author
Member

quick update to the diff: object duplication wasn't correctly handled

new patch:
freestyle_iterator_fix_v2.diff

quick update to the diff: object duplication wasn't correctly handled new patch: [freestyle_iterator_fix_v2.diff](https://archive.blender.org/developer/F68340/freestyle_iterator_fix_v2.diff)

Added subscriber: @mont29

Added subscriber: @mont29

@flokkievids: For patches, creating diff (https://developer.blender.org/differential/diff/create/) is usually a better solution, helps the reviewing process. ;)

@flokkievids: For patches, creating diff (https://developer.blender.org/differential/diff/create/) is usually a better solution, helps the reviewing process. ;)
Author
Member

@mont29 : thanks, I created [D222](https://developer.blender.org/D222) with an updated version.

@mont29 : thanks, I created [[D222](https://archive.blender.org/developer/D222)](https://developer.blender.org/D222) with an updated version.

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

I have just pushed the proposed changes in D222 through 5 separate commits a169989, 41d778f, bab88fe, e9e2813, and b58beed.
Many thanks to @flokkievids for the contribution and sustained efforts on code revisions!

I have just pushed the proposed changes in [D222](https://archive.blender.org/developer/D222) through 5 separate commits a169989, 41d778f, bab88fe, e9e2813, and b58beed. Many thanks to @flokkievids for the contribution and sustained efforts on code revisions!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#38213
No description provided.