Skip to content
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

Crash when instantation PCells from Python code #646

Closed
klayoutmatthias opened this issue Sep 22, 2020 · 0 comments
Closed

Crash when instantation PCells from Python code #646

klayoutmatthias opened this issue Sep 22, 2020 · 0 comments
Milestone

Comments

@klayoutmatthias
Copy link
Collaborator

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()
klayoutmatthias added a commit that referenced this issue Nov 25, 2020
The issue was mainly caused by a "cleanup" call on
the library. Cleanup is supposed to remove excess
top level PCell variants. For libraries this is not
possible, as the library does not know which variants
are used and which are not.

In addition, some hardening against segfaults in
case of defect layouts has been applied.
@klayoutmatthias klayoutmatthias added this to the 0.26.9 milestone Nov 25, 2020
klayoutmatthias added a commit that referenced this issue Nov 27, 2020
* Fixed a compiler warning

* Fixed #646 (crash on PCell Library "delete")

The issue was mainly caused by a "cleanup" call on
the library. Cleanup is supposed to remove excess
top level PCell variants. For libraries this is not
possible, as the library does not know which variants
are used and which are not.

In addition, some hardening against segfaults in
case of defect layouts has been applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant