Skip to content

Crash when loading library with mabrains klayout_lib_manager #2156

Closed

Description

@martinjankoehler
Crash log written to /headless/.klayout/klayout_crash.log

../../../src/layui/layui/layCellTreeModel.cc,446,! mp_layout->under_construction () && ! (mp_layout->manager () && mp_layout->manager ()->transacting ())
ERROR: Exception caught: Internal error: ../../../src/layui/layui/layCellTreeModel.cc:446 ! mp_layout->under_construction () && ! (mp_layout->manager () && mp_layout->manager ()->transacting ()) was not true

message-3.txt

Design:
bug.zip


BTW, the klayout_crash.log is missing the most relevant portion with the internal error.

Image

Activity

  1. klayoutmatthias commented on Sep 24, 2025

    @klayoutmatthias
    Collaborator

    The internal error is basically just an error and recoverable, but the crash is a different thing. It is probably a consequence of some underlying deeper problem.

    One cause for this particular issue maybe a RecursiveShapeIterator or RecursiveInstanceIterator that is still active while something is trying to modify a layout. KLayout locks the layout against internal updates during that phase. The error says that the layout is locked, but something triggered a modification that requires an update - for example creating or deleting a cell. That usually breaks the internal structure of the layout which the iterator depends on an will kill the application.

    Holding an iterator object is in particular a problem in Ruby, because the GC does not immediately destroy any object held by a reference. In Ruby, using a code block on the iterator ("each") is a good option to avoid that problem. Otherwise, it's possible to explicitly free an iterator with "iter._destroy()".

    Matthias

  2. klayoutmatthias commented on Sep 25, 2025

    @klayoutmatthias
    Collaborator

    Hmm ... here is how I cannot reproduce it:

    1.) git clone https://github.com/mabrains/klayout_lib_manger.git
    2.) cd klayout_lib_manger/
    3.) klayout -rm library_manager.rb
    4.) Choose "Load Libraries" from the tool bar, use "libs.json"
    5.) Load "ring.gds" using "File/Open"
    6.) Choose "Open Library"

    No crash :(

    My system is Ubuntu 24.04.

    Matthias

  3. klayoutmatthias commented on Sep 25, 2025

    @klayoutmatthias
    Collaborator

    Okay, but I can reproduce it with your case.

    I will debug the issue.

    Matthias

  4. klayoutmatthias commented on Sep 25, 2025

    @klayoutmatthias
    Collaborator

    Okay, that was easy :)

    Problem #1: Layout#delete_cell is not safeguarded. If you pass a cell index of an invalid cell, KLayout crashes (-> enhancement)

    Problem #2: The library manager tries to delete cells it has substituted, but the array of cells to delete may contain the same cell multiple times. Hence, after deleting the cell once, the second attempt to delete the same cell crashes KLayout.

    Here is my patch to the library manager that fixes the problem:

    diff --git a/library_manager.rb b/library_manager.rb
    index a48b35d..53da3d4 100644
    --- a/library_manager.rb
    +++ b/library_manager.rb
    @@ -155,9 +155,7 @@ relink_action.on_triggered do
         end
       end
     
    -  cells_to_remove.each do |c|
    -    layout.delete_cell(c)
    -  end
    +  layout.delete_cells(cells_to_remove.sort.uniq)
     
       layout.end_changes
       cv.show_layout(layout, false)
    

    Matthias

  5. added this to the 0.30.5 milestone on Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions