Skip to content

Unsafe iteration of instances with flatten #200

@klayoutmatthias

Description

@klayoutmatthias

The following code gives an error when run with the attached layout:

lv = RBA::Application.instance.main_window.current_view
lay = lv.cellview(lv.active_cellview_index).layout
top = lay.top_cell

top.each_inst  do |ci|
  cname = ci.cell.name
  if (cname.start_with?("Circle"))
    ci.flatten
  end
end

This solution works fine:

lv = RBA::Application.instance.main_window.current_view
lay = lv.cellview(lv.active_cellview_index).layout
top = lay.top_cell

insts_to_flatten = []
top.each_inst  do |ci|
  cname = ci.cell.name
  if (cname.start_with?("Circle"))
    insts_to_flatten << ci
  end
end

insts_to_flatten.each do |ci|
  ci.flatten(8)
end

In general, iteration of a container (the instances) is unsafe while it's modified (in flatten which removes instances). However, in this case, the duplicate cell instance seems to cause the issue.

Maybe there is a reason to rectify this issue and allow iteration during manipulation. This would be more intuitive.

test.gds.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions