Segfault on creating square filled zone with python interface

Bug #1828119 reported by Richard Graham
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Unknown

Bug Description

When using the python interface, Kicad crashes with a segfault following refresh when a filled zone is added in some cases.

Following code is a minimal example reproducing the problem:

import pcbnew
from pcbnew import FromMM

board = pcbnew.GetBoard()
zone = pcbnew.ZONE_CONTAINER(board)
sps = pcbnew.SHAPE_POLY_SET()
chain = pcbnew.SHAPE_LINE_CHAIN()
chain.Append( FromMM(0.0), FromMM(0.0) )
chain.Append( FromMM(20.0), FromMM(0.0) )
chain.Append( FromMM(20.0), FromMM(20.0) )
chain.Append( FromMM(0.0), FromMM(20.0) )
chain.SetClosed(True)
sps.AddOutline(chain)
zone.SetOutline(sps)
board.Add(zone)
pcbnew.Refresh()

Interestingly, problem only occurs when the shape is square, i.e. when last chain append is to (0.0,20) as above. If changed to (0.1, 20), or omitted (to make a triangle) then it works fine.

Application: kicad
Version: 6.0.0-unknown-r15606.f1a38a6d4.fc30, debug build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.64.0 OpenSSL/1.1.1b zlib/1.2.11 brotli/1.0.7 libidn2/2.1.1 libpsl/0.20.2 (+libidn2/2.0.5) libssh/0.8.7/openssl/zlib nghttp2/1.38.0
Platform: Linux 5.0.11-300.fc30.x86_64 x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.69.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.64.0
    Compiler: GCC 9.0.1 with C++ ABI 1013

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_PYTHON3=OFF
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_WXPYTHON_PHOENIX=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

Tags: pcbnew python
Richard Graham (rdg37)
description: updated
Jon Evans (craftyjon)
Changed in kicad:
importance: Undecided → Critical
tags: added: pcbnew python
Changed in kicad:
milestone: none → 6.0.0-rc1
Revision history for this message
Seth Hillbrand (sethh) wrote :

I am unable to recreate this. Do you still observe the same behavior?

Application: Pcbnew
Version: (5.1.0-1256-g39954b20f), release build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.64.0 OpenSSL/1.1.1c zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.36.0 librtmp/2.3
Platform: Linux 4.19.0-5-amd64 x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
    Boost: 1.67.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.64.0
    Compiler: GCC 8.3.0 with C++ ABI 1013

Build settings:
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_PYTHON3=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

Changed in kicad:
status: New → Incomplete
Changed in kicad:
milestone: 6.0.0-rc1 → none
Revision history for this message
Richard Graham (rdg37) wrote :

My apologizes, I didn't see this response earlier.

I have just tested with:
  * Version: (5.1.0-rc2-24-gdb31b7902)
  * Version: (5.1.0-1305-gc84c10fa0)
both with python 3. Full version info tested is attached.

I can confirm that I do *not* see this bug with either of these versions and can't replicate.

However, the original bug I reported was with a 6.0 pre-release (r15606) which I was testing back then and no longer have access to.

If you could point me to the equivalent 6.0 branch for testing I would be happy to build it and test again. I am confused about the branches and version numbering.

Just speculating here, but my hunch is that this is probably something to do with detecting if a shape is open or closed or something similar; perhaps failing on some exact case with exactly equal successive coordinates in one dimension. If that is the case, then would that be something handled by OpenCascade? I notice that the OpenCascade version has bumped up a lot (6.9.1 -> 7.3.0) between the build I saw the bug with and now. So perhaps they have fixed it.

Revision history for this message
Seth Hillbrand (sethh) wrote :

(5.1.0-1305-gc84c10fa0) is the newer version of the 6.0 development that you were using previously.

The major difference looks like Python version here. This doesn't crash in Python3, which is used in the new Ubuntu builds.

We should test with Python2 before marking this fixed.

Changed in kicad:
milestone: none → 6.0.0-rc1
Revision history for this message
jean-pierre charras (jp-charras) wrote :

In fact the script is incorrect.
a working script (although not a very good script) is:

import pcbnew
from pcbnew import FromMM
board = pcbnew.GetBoard()
zone = pcbnew.ZONE_CONTAINER(board)

sps = zone.Outline() #pcbnew.SHAPE_POLY_SET()
chain = pcbnew.SHAPE_LINE_CHAIN()
chain.Append( FromMM(0.0), FromMM(0.0) )
chain.Append( FromMM(20.0), FromMM(0.0) )
chain.Append( FromMM(20.0), FromMM(20.0) )
chain.Append( FromMM(0.0), FromMM(20.0) )
chain.SetClosed(True)
sps.AddOutline(chain)
#zone.SetOutline(sps)
board.Add(zone)
pcbnew.Refresh()

Incorrect lines are commented.
The crash is for me something like a double deletion:
AddOutline() is an accessor to a private variable, and its use here is fully incorrect.

Revision history for this message
KiCad Janitor (kicad-janitor) wrote :

KiCad bug tracker has moved to Gitlab. This report is now available here: https://gitlab.com/kicad/code/kicad/-/issues/1750

Changed in kicad:
status: Incomplete → Expired
Changed in kicad:
importance: Critical → Unknown
status: Expired → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.