Possible bug

edited April 2014 in Ruby Scripting

Hi,

When I run the following code (with an existing and valid library and cellname), it works great, and the cell is placed into the active layout.

However, when I then manually select the just-placed cell and delete it (with the delete key), then run the script again, KLayout crashes (Windows says "klayout.exe has stopped working" and it closes).

include RBA
layout_view = RBA::Application.instance.main_window.current_view
layout = layout_view.active_cellview.layout
out_cell = layout_view.active_cellview.cell
layer = LayerInfo::new(1,0)
lib = Library.library_by_name('Libname')
lib_cell_index = lib.layout.cell_by_name('Cellname')
layout.add_lib_cell(lib,lib_cell_index)
cia = RBA::CellInstArray.new(lib_cell_index,RBA::Trans.new)
inst = out_cell.insert(cia)

If I run this script 3 times, it creates 3 instances. I can keep deleting these and running EXCEPT when I delete the last remaining instance, then the following time, it crashes. In other words, if you have added "n" instances and deleted "m != n" instances, it's fine to run again. If you add "n" instances and delete "n" instances then it crashes.

KLayout 0.23.3, Windows 7.

Any ideas?

Thanks!

Comments

  • edited April 2014

    Hi David,

    there is a tiny, but severe bug in the script:

    lib_proxy = layout.add_lib_cell(lib,lib_cell_index)
    cia = RBA::CellInstArray.new(lib_proxy,RBA::Trans.new)
    

    In other words: don't instantiate the cell from the library, but the cell you get from "add_lib_cell".

    Let me explain: a library is basically a layout for it's own. "lib_cell_index" is the index of the target cell in the library. But the index is only valid in the context of this layout. In order to refer to a library cell, you create a "proxy cell" with "add_lib_cell". This cell lives in your working layout. A proxy cell is similar to a symbolic link in a Linux file system - it looks like an ordinary cell, but the content is taken from somewhere else. The proxy cell is the cell you need to instantiate.

    BTW: I started to provided alternative methods for some functions that use Cell objects rather than cell indexes. Cell objects carry a link to their layout domain, hence allow to detect these kind of issues. However, the API is not consistently updated yet.

    Regards,

    Matthias

Sign In or Register to comment.