Skip to content

Crash when instantation PCells from Python code #646

@klayoutmatthias

Description

@klayoutmatthias

For details see here: https://www.klayout.de/forum/discussion/1377/deep-deleting-everything-in-the-layout-as-well-as-the-layout-itself-python#latest

The code that makes the application crash is this:

import pya

class PCell1(pya.PCellDeclarationHelper):

  def produce_impl(self):
    pass

  def display_text_impl(self):
    return "PCell1"

class PCell2(pya.PCellDeclarationHelper):

  def produce_impl(self):
    cell = self.layout.create_cell("PCell1", "PCell1Library", {})
    self.cell.insert(pya.DCellInstArray(cell.cell_index(), pya.DTrans()))

  def display_text_impl(self):
    return "PCell2"

def create_libraries():
  library1 = pya.Library()
  library1.description = "Test library"
  library1.layout().register_pcell("PCell1", PCell1())
  library1.register("PCell1Library")
  library2 =  pya.Library()
  library2.description = "Test library"
  library2.layout().register_pcell("PCell2", PCell2())
  library2.register("PCell2Library")

def reload_libraries():
  mw = pya.MainWindow.instance()
  #mw.close_all() # uncommenting this fixes problem in this case, but not in more complex situations
  library1 = pya.Library.library_by_name("PCell1Library")
  library1.delete()
  library2 = pya.Library.library_by_name("PCell2Library")
  library2.delete()
  create_libraries()
  mw.create_layout(1)

def create_pcell():
  cell_view = pya.CellView.active()
  layout = cell_view.layout()
  cell = layout.create_cell("PCell2", "PCell2Library", {})
  cell_view.cell = cell

pya.MainWindow.instance().create_layout(1)
create_libraries()
create_pcell()
reload_libraries()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions