klayout icon indicating copy to clipboard operation
klayout copied to clipboard

Deleting cells: 'basic_string: construction from null is not valid'

Open patrickschulz opened this issue 3 years ago • 4 comments
trafficstars

Whenever I'm deleting any cells, I get this message, which is problematic since I can not delete a bunch of cells simultaneously. There is a similar issue (https://github.com/KLayout/klayout/issues/1099), but in my case this does not have to do anything with any PDK or pcells. I can reproduce this with a fresh config, I use the (default) technology and inserted an empty cell in the toplevel layout. When I delete that, I get this error.

My setup: arch linux (kernel 5.19.11) klayout 0.27.11 ruby 2.7 qt 5.15

Kind regards, Patrick

patrickschulz avatar Sep 29 '22 14:09 patrickschulz

Thanks for this report

However I seem not to be able to reproduce it (0.27.12, Ubuntu-22). Here is what I did:

KLAYOUT_HOME=/dev/null klayout -e

(KLAYOUT_HOME=/dev/null forces default config).

Then:

  • File/New Layout
  • Right click on cell list -> New Cell, call it "A"
  • Select cell A, right click on cell list -> Delete Cell

There is no error message :(

klayoutmatthias avatar Sep 29 '22 17:09 klayoutmatthias

Thanks for your quick reply. I tried it again exactly like you, unfortunately I can reproduce this even then... Is there a way to see where this error is coming from? I've tried setting a higher debug level but the result is not really helpful to me. I looked through it but nothing caught my eye. I'm happy to dig deeper, but I need some pointer on how to do that.

patrickschulz avatar Sep 29 '22 20:09 patrickschulz

The message is pretty generic - it says that a std::string has been created from a null const char *.

I can see the error on an archlinux docker image with klayout from the package repo. I'll try to debug the problem.

Matthias

klayoutmatthias avatar Sep 30 '22 17:09 klayoutmatthias

Okay, found the problem ... praise Docker! :)

Here is a lecture for C++ users on things to be careful with.

Line 848 of dbLayout.cc is this:

848	      manager ()->queue (this, new NewRemoveCellOp (*c, cell_name (*c), true /*remove*/, take_cell (*c)));

So what happens is that take_cell(*c) removes the cell from the cell stack, cell_name(*c) reads the name of the the cell indicated by *c. C++ is basically free to evaluate the argument expressions in any order. So on my systems (Ubuntu with gcc 11.2 and clang, Windows, CentOS etc.), apparently the compiler evaluates the arguments in the given order. I.e. cell_name before take_cell and everything is fine. On archlinux (gcc 12.2) the order appears to be the other way and take_cell removes the cell before cell_name tries to read it. That causes this exception.

So the fix is simply to make sure cell_name is called before take_cell.

Thanks for reporting this issue.

Matthias

klayoutmatthias avatar Sep 30 '22 20:09 klayoutmatthias

Any change we could get a new 0.27.11 release with this patch?

I see it on Arch and Debian

https://github.com/KLayout/klayout/issues/1176

joamatab avatar Oct 31 '22 18:10 joamatab

Was released with 0.27.12

klayoutmatthias avatar Nov 30 '22 21:11 klayoutmatthias