diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index bcd76d706..3c16a85ed 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -2526,10 +2526,25 @@ Layout::register_pcell (const std::string &name, pcell_declaration_type *declara // replace any existing PCell declaration with that name. id = pcid->second; if (m_pcells [id]) { - delete m_pcells [id]; - } - m_pcells [id] = new pcell_header_type (id, name, declaration); + std::unique_ptr org_header (m_pcells [id]); + std::vector variants; + for (auto v = org_header->begin (); v != org_header->end (); ++v) { + variants.push_back (v->second); + } + for (auto v = variants.begin (); v != variants.end (); ++v) { + (*v)->unregister (); + } + + m_pcells [id] = new pcell_header_type (id, name, declaration); + + for (auto v = variants.begin (); v != variants.end (); ++v) { + (*v)->reregister (); + } + + } else { + m_pcells [id] = new pcell_header_type (id, name, declaration); + } } else { diff --git a/testdata/ruby/dbPCells.rb b/testdata/ruby/dbPCells.rb index 281eaf451..afbc7f2f2 100644 --- a/testdata/ruby/dbPCells.rb +++ b/testdata/ruby/dbPCells.rb @@ -774,6 +774,41 @@ class DBPCell_TestClass < TestBase end + def test_11 + + lib = CircleLib1782::new("CircleLib") + + ly = RBA::Layout::new + + top = ly.create_cell("TOP") + + names = [] + + c = ly.create_cell("Circle", "CircleLib", { "l" => RBA::LayerInfo::new(1, 0), "r" => 2.0, "n" => 64 }) + + # triggered another flavor of #1782 + lib.reregister_pcell + + c = ly.create_cell("Circle", "CircleLib", { "l" => RBA::LayerInfo::new(1, 0), "r" => 2.0, "n" => 64 }) + top.insert(RBA::DCellInstArray::new(c, RBA::DTrans::new())) + + tmp = File::join($ut_testtmp, "tmp.gds") + ly.write(tmp) + + # this should not throw an internal error + ly._destroy + + # we should be able to read the Layout back + ly = RBA::Layout::new + ly.read(tmp) + assert_equal(ly.top_cell.name, "TOP") + assert_equal(ly.cells, 2) + ly._destroy + + lib._destroy + + end + end load("test_epilogue.rb")