New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsafe iteration of instances with flatten #200

Closed
klayoutmatthias opened this Issue Nov 26, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@klayoutmatthias
Copy link
Collaborator

klayoutmatthias commented Nov 26, 2018

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

klayoutmatthias added a commit that referenced this issue Jan 9, 2019

Merge pull request #221 from KLayout/issue-200
Fixed #200 by introducing layout locking during iteration

klayoutmatthias added a commit that referenced this issue Jan 10, 2019

Fixed #200 by introducing layout locking during iteration
The cause for the problem was that the layout got updated
while iterating causing the mess within the iterator.

This solution is to lock the layout while an iterator
is present. This happens for various Cell and Shapes
iterator, so it's a major enhancement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment