[SOLVED] Python command 'pcb.RemoveNative': core dump in Linux & Kicad 5.99

Hi,
using some plugins I noticed an issue when using the pcb.RemoveNative function.
The issue can be tested using i.e. Via Stitching plugin and clicking on ‘Delete Vias’ button.
I’ve created a sample plugin DeleteViasTest to test the issue, and a sample board pcb-with-vias.kicad_pcb
Anyway, the issue can be tested using the following code on the sample board:

import pcbnew
pcb = pcbnew.GetBoard() 
tracks=pcb.GetTracks()
for track in tracks:
    pcb.RemoveNative(track)
pcbnew.Refresh()

When using this code on K 5.99 Win, everything goes fine. On Linux instead I get that the code will not delete all the vias, but only some…
Using the Via Stitching Delete button I can even get a core dump.
Segmentation fault (core dumped)

Here my Linux info:

Application: Pcbnew
Version: 5.99.0-unknown-3fffd04~100~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-51-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
Build date: Oct 21 2019 11:53:42
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.22
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.4.0 with C++ ABI 1011
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

Since you are 192 commits behind I suggest you re-compile/update to reflect the most recent changes. Things should be better after that.

Already tested… nothing changes… could you please test it in your environment?

If it still is broken on the recent commits, please file a bug report about it. There have been some changes to object deletion in the master branch, and so this could be a result of those. We can only fix the things that we know are broken.

As suggested, I’m trying to get some confirm here, before reporting…
Could someone test it on his/her system?

Got this with todays breakfast compile. Hope it can shed some light on the issue.

  • Nov 5 11:23:45 amd64 kernel: [1190739.756763] kicad[1114]: segfault at 30df0 ip 00007fefdcae4cd4 sp 00007fff776faf00 error 4 in _pcbnew.kiface[7fefdbf78000+15d4000]

Application: KiCad
Version: (5.99.0-295-g076948f8e), release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 GnuTLS/3.5.18 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-66-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
Build date: Nov 5 2019 10:40:35
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.22
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 9.2.1 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

@maui-

The code doesn’t crash my machine but I see how it might.

You are deleting while iterating over a list. This will invalidate the iterators in C++. I’d recommend copying the items to be deleted into a second list and then removing them from there.

Thanks @Seth_h
the following code seems to work reliably also on k 5.99

pcb = pcbnew.GetBoard() 
tracks=pcb.GetTracks()
tracks_cp = list(tracks)
l = len (tracks_cp)
for i in range(l):
    pcb.RemoveNative(tracks_cp[i])
pcbnew.Refresh()

But I noticed that if I change

pcb.RemoveNative(tracks_cp[i])
to
pcb.DeleteNative(tracks_cp[i])

I still get Segmentation fault (core dumped) on k 5.99
Is there a different implementation on RemoveNative vs DeleteNative?

The RemoveNative() and DeleteNative() are wrappers around the C++ code to allow python-safe implementations as Remove() and Delete() . DeleteNative() will free the item from memory. But Python still owns it’s reference, so you get a segfault. The Pythonic Delete() wrapper will release the ownership first, then call DeleteNative() .

Thanks again for your reply :smiley:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.