You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash when loading library with mabrains klayout_lib_manager #2156
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()".
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"
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)
Activity
klayoutmatthias commentedon Sep 24, 2025
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
klayoutmatthias commentedon Sep 25, 2025
Hmm ... here is how I cannot reproduce it:
1.)
git clone https://github.com/mabrains/klayout_lib_manger.git2.)
cd klayout_lib_manger/3.)
klayout -rm library_manager.rb4.) 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
klayoutmatthias commentedon Sep 25, 2025
Okay, but I can reproduce it with your case.
I will debug the issue.
Matthias
klayoutmatthias commentedon Sep 25, 2025
Okay, that was easy :)
Problem #1:
Layout#delete_cellis 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:
Matthias