Skip to content

Segfault with layer list manipulation while iterating #368

@klayoutmatthias

Description

@klayoutmatthias

This code segfaults on typical layer lists:

lv = pya.LayoutView.current()
  
to_delete = []
for l in lv.each_layer():
  if l.source_layer % 2 == 0:
    to_delete.append(l)

for l in to_delete:
  l.delete()

Reason: deleting a layer will invalidate the following iterators. That's reasonable, but the program should not segfault. The solution is to reverse:

...
to_delete.reverse()
for l in to_delete:
  l.delete()

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions