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

Internal error: ../../../src/db/db/ _cut_polygon_internal (poly, line, right_of_line) was not true #166

lukasc-ubc opened this issue Sep 12, 2018 · 2 comments


Copy link

lukasc-ubc commented Sep 12, 2018

In KLayout 0.25.4, MacOS:

  • I created a layout in GDS

  • ran a script to do an inversion

  • Saved the GDS, and received the above error

  • Saved the file as a DXF, and that works

  • Closed and opened the DXF

  • Tried saving again as a GDS, and same error

  • I also tried to clean up the polygons by doing "Merge Shapes", and that didn't help.

Edit: It would be nice if there was a utility that checked for strange polygon things, such as in the above layout. By doing a "Size Shape" 0.001 and -0.001, I was able to get it to save.

Copy link

Hi Lukas,

This error means the polygon cut algorithm which reduces the number of points down to the maximum allowed number encountered a weired situation it cannot resolve. If you used boolean operations, these situations should not arise as the resulting polygons are merged. I'll check the test case. Thanks for providing it.

DXF works because it does not have a maximum vertex count. The same holds for OASIS and CIF.

Best regards,


Copy link

Hi Lukas,

I was able to fix the issue. The reason was actually a rounding issue: the small gaps that appear in the output are sometimes closed when the polygon cut algorithm splits the polygons due to cut-point snapping. This induces a topology change that the algorithm is not expecting. I can fix this by using a higher precision internally.

I can now save your layout even with a max vertex count of 4 which gives a funny fractured layout. But XOR-wise it's (almost, within 1 DBU) the same than the original :-)


klayoutmatthias added a commit that referenced this issue Sep 16, 2018
klayoutmatthias added a commit that referenced this issue Sep 16, 2018
klayoutmatthias added a commit that referenced this issue Sep 26, 2018
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 9, 2018
0.25.6          (2018-11-23):

* Enhancement: KLayout/klayout#199
       Added an option to export DXF polygons as LINE objects
* Bugfix: KLayout/klayout#198
       Stitching of DXF contours wasn't taking nearest neighbours
* Bugfix: KLayout/klayout#191
       MainWindow/PluginRoot classes got mixed up
       As a side effect of this fix, layout views can now
       be configured individually. This wasn't working
       consistently before.

0.25.5          (2018-10-20):

* Bugfix: KLayout/klayout#162
       GDS2 LIBNAME was not maintained on "File/Save".
* Bugfix: KLayout/klayout#166
       Internal error when writing GDS files (breaking of polygons)
* Bugfix: KLayout/klayout#172
       DEF reader did not pull vias from LEF
* Bugfix: KLayout/klayout#174
       Performance issue with many layers with width >1
* Bugfix: KLayout/klayout#176
       Painting issue with texts
* Bugfix: KLayout/klayout#185
       Hash values available as __hash__ standard method now
       for Python
* Bugfix: some potential memory corruption issues fixed
       During the efforts for making the code base compatible
       with MSVC, some potential candidates for memory corruption
       have been identified and fixed.
       These fixes are included in this release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants