wxPython crashes with Segmentation fault

3

I'm confused to why my application crashes with Segmentation fault. I have a python app using wxPython for front end. My application crashes randomly with segmentation fault and I know it has to be wxPython because I have a console version of the same code and it doesn't crash. The front end is a read-only table with items populating it automatically from a thread.

I'm using wxPython2.8 and python version 3.0 and I'm running it on Ubuntu 10.04. And I can't tell if I'm doing something wrong or is it wxPython and if so should I report a bug?

I ran the application in eclipse debug mode and after some time running got this:

Gdk:ERROR:/build/buildd/gtk+2.0-2.20.1/gdk/gdkregion-generic.c:337:miSetExtents: assertion failed: (pExtents->y1 < pExtents->y2)

I also ran it using gdb by installing python3.1-gdb , apt-get install python3.1-gdb and got this:

Program received signal SIGSEGV, Segmentation fault. 
0xb76dcfa7 in wxGridCellAttr::GetRenderer(wxGrid*, int, int) const () from /usr/lib/libwx_gtk2u_adv-2.8.so.0

The second time I ran with gdb and called bt I got this:

Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c71b70 (LWP 10119)]
[New Thread 0xb53e4b70 (LWP 10120)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb5c71b70 (LWP 10119)]
0x00000061 in ?? ()
(gdb) bt
#0  0x00000061 in ?? ()
#1  0xb76e8209 in wxGrid::GetCellSize(int, int, int*, int*) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#2  0xb76e82bb in wxGrid::CellToRect(int, int) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#3  0xb76f6ee5 in wxGrid::SetCellValue(int, int, wxString const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#4  0xb607c45b in ?? () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_grid.so
#5  0x080e0a57 in PyEval_EvalFrameEx ()
#6  0x080e2977 in PyEval_EvalCodeEx ()
#7  0x080e0fb3 in PyEval_EvalFrameEx ()
#8  0x080e20e7 in PyEval_EvalFrameEx ()
#9  0x080e2977 in PyEval_EvalCodeEx ()
#10 0x0816bdbf in ?? ()
#11 0x0806257a in PyObject_Call ()
#12 0x080df8d8 in PyEval_EvalFrameEx ()
#13 0x080e20e7 in PyEval_EvalFrameEx ()
#14 0x080e20e7 in PyEval_EvalFrameEx ()
#15 0x080e2977 in PyEval_EvalCodeEx ()
#16 0x0816bcdc in ?? ()
#17 0x0806257a in PyObject_Call ()
#18 0x0806a57c in ?? ()
#19 0x0806257a in PyObject_Call ()
#20 0x080db9f2 in PyEval_CallObjectWithKeywords ()
#21 0x0810ecf8 in ?? ()
#22 0xb7fb096e in start_thread (arg=0xb5c71b70) at pthread_create.c:300
#23 0xb7d3d3fe in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

The third time I ran it with bt again I got this:

Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c70b70 (LWP 13774)]
[New Thread 0xb53e3b70 (LWP 13826)]
*** glibc detected *** /usr/bin/python: double free or corruption (!prev): 0x08aec2b0
Program received signal SIGSEGV, Segmentation fault.
0xb72abcf0 in typeinfo name for wxObject () from /usr/lib/libwx_baseu-2.8.so.0
(gdb) bt
#0  0xb72abcf0 in typeinfo name for wxObject () from /usr/lib/libwx_baseu-2.8.so.0
#1  0xb76dbe59 in wxGridCellAttr::GetBackgroundColour() const () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#2  0xb76e4c8b in wxGridCellRenderer::Draw(wxGrid&, wxGridCellAttr&, wxDC&, wxRect const&, int, int, bool) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#3  0xb76f2ea4 in wxGridCellStringRenderer::Draw(wxGrid&, wxGridCellAttr&, wxDC&, wxRect const&, int, int, bool) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#4  0xb76eb579 in wxGrid::DrawCell(wxDC&, wxGridCellCoords const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#5  0xb76eb882 in wxGrid::DrawGridCellArea(wxDC&, wxGridCellCoordsArray const&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#6  0xb76ece37 in wxGridWindow::OnPaint(wxPaintEvent&) () from /usr/lib/libwx_gtk2u_adv-2.8.so.0
#7  0xb71eba9f in wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&), wxEvent&) const () from /usr/lib/libwx_baseu-2.8.so.0
#8  0xb728a209 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from /usr/lib/libwx_baseu-2.8.so.0
#9  0xb728b2d4 in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () from /usr/lib/libwx_baseu-2.8.so.0
#10 0xb728b3d3 in wxEvtHandler::ProcessEvent(wxEvent&) () from /usr/lib/libwx_baseu-2.8.so.0
#11 0xb74770c2 in wxWindow::GtkSendPaintEvents() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#12 0xb7477688 in ?? () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#13 0xb6dfa434 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#14 0xb6a0f252 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#15 0xb6a2399d in ?? () from /usr/lib/libgobject-2.0.so.0
#16 0xb6a24c33 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#17 0xb6a25256 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#18 0xb6f27646 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#19 0xb6df412b in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#20 0xb6c6284b in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#21 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#22 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#23 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#24 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#25 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#26 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#27 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#28 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#29 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#30 0xb6c627fa in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#31 0xb6c8bad4 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#32 0xb6c5efa3 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#33 0xb6c60fbf in gdk_window_process_all_updates () from /usr/lib/libgdk-x11-2.0.so.0
#34 0xb6c6103b in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#35 0xb6c3d358 in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#36 0xb695f661 in ?? () from /lib/libglib-2.0.so.0
#37 0xb69616e5 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#38 0xb69653d8 in ?? () from /lib/libglib-2.0.so.0
#39 0xb6965917 in g_main_loop_run () from /lib/libglib-2.0.so.0
#40 0xb6df43d9 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#41 0xb7460708 in wxEventLoop::Run() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#42 0xb74f34de in wxAppBase::MainLoop() () from /usr/lib/libwx_gtk2u_core-2.8.so.0
#43 0xb7a15b92 in wxPyApp::MainLoop() () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core_.so
#44 0xb7a889da in ?? () from /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core_.so
#45 0x080e0a57 in PyEval_EvalFrameEx ()
#46 0x080e2977 in PyEval_EvalCodeEx ()
#47 0x0816bcdc in ?? ()
#48 0x0806257a in PyObject_Call ()
#49 0x0806a57c in ?? ()
#50 0x0806257a in PyObject_Call ()
#51 0x080e0599 in PyEval_EvalFrameEx ()
#52 0x080e20e7 in PyEval_EvalFrameEx ()
#53 0x080e20e7 in PyEval_EvalFrameEx ()
#54 0x080e20e7 in PyEval_EvalFrameEx ()
#55 0x080e2977 in PyEval_EvalCodeEx ()
#56 0x080e2a77 in PyEval_EvalCode ()
#57 0x0810071d in PyRun_FileExFlags ()
#58 0x08100982 in PyRun_SimpleFileExFlags ()
#59 0x0805df7c in Py_Main ()
#60 0x0805d13b in main ()

and the last time I ran I actually got a __kernel_vsyscall:

Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
Starting program: /usr/bin/python main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c71b70 (LWP 20640)]
[New Thread 0xb53e4b70 (LWP 20662)]
*** glibc detected *** /usr/bin/python: double free or corruption (!prev): 0x08aec298 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6e341)[0xb7cd8341]
/lib/tls/i686/cmov/libc.so.6(+0x6fb98)[0xb7cd9b98]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb7cdcc7d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb716d741]
/usr/lib/libwx_baseu-2.8.so.0(_ZN21wxClientDataContainerD0Ev+0x33)[0xb71ee293]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid11GetCellSizeEiiPiS0_+0x59)[0xb76e8209]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid10CellToRectEii+0xab)[0xb76e82bb]
/usr/lib/libwx_gtk2u_adv-2.8.so.0(_ZN6wxGrid12SetCellValueEiiRK8wxString+0x85)[0xb76f6ee5]
/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_grid.so(+0x1f45b)[0xb607c45b]
/usr/bin/python(PyEval_EvalFrameEx+0x40f7)[0x80e0a57]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python(PyEval_EvalFrameEx+0x4653)[0x80e0fb3]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python[0x816bdbf]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python(PyEval_EvalFrameEx+0x2f78)[0x80df8d8]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalFrameEx+0x5787)[0x80e20e7]
/usr/bin/python(PyEval_EvalCodeEx+0x857)[0x80e2977]
/usr/bin/python[0x816bcdc]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python[0x806a57c]
/usr/bin/python(PyObject_Call+0x4a)[0x806257a]
/usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80db9f2]
/usr/bin/python[0x810ecf8]
/lib/tls/i686/cmov/libpthread.so.0(+0x596e)[0xb7fb096e]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0xb7d3d3fe]
======= Memory map: ========
08048000-08229000 r-xp 00000000 08:01 12322846   /usr/bin/python2.6
08229000-0822a000 r--p 001e0000 08:01 12322846   /usr/bin/python2.6
0822a000-08279000 rw-p 001e1000 08:01 12322846   /usr/bin/python2.6
08279000-08b35000 rw-p 00000000 00:00 0          [heap]
b4a00000-b4a7b000 rw-p 00000000 00:00 0 
b4a7b000-b4b00000 ---p 00000000 00:00 0 
b4bb2000-b4be0000 r-xp 00000000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be0000-b4be2000 r--p 0002d000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be2000-b4be3000 rw-p 0002f000 08:01 12717595   /usr/lib/python2.6/lib-dynload/pyexpat.so
b4be3000-b4be4000 rw-p 00000000 00:00 0 
b4be4000-b4be5000 ---p 00000000 00:00 0 
b4be5000-b53e5000 rw-p 00000000 00:00 0 
b53e5000-b5471000 r--p 00000000 08:01 13370974   /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
b5471000-b5472000 ---p 00000000 00:00 0 
b5472000-b5c72000 rw-p 00000000 00:00 0 
b5c72000-b5d0a000 r--p 00000000 08:01 13370975   /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
b5d0a000-b5d14000 r-xp 00000000 08:01 4718773    /lib/libudev.so.0.6.1
b5d14000-b5d15000 r--p 00009000 08:01 4718773    /lib/libudev.so.0.6.1
b5d15000-b5d16000 rw-p 0000a000 08:01 4718773    /lib/libudev.so.0.6.1
b5d16000-b5d3a000 r-xp 00000000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3a000-b5d3b000 r--p 00023000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3b000-b5d3c000 rw-p 00024000 08:01 12327322   /usr/lib/gio/modules/libgvfsdbus.so
b5d3c000-b5d50000 r-xp 00000000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d50000-b5d51000 r--p 00013000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d51000-b5d52000 rw-p 00014000 08:01 12324166   /usr/lib/libgvfscommon.so.0.0.0
b5d6e000-b5da5000 r-xp 00000000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da5000-b5da6000 r--p 00036000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da6000-b5da7000 rw-p 00037000 08:01 4718707    /lib/libdbus-1.so.3.4.0
b5da7000-b5de0000 r-xp 00000000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de0000-b5de1000 r--p 00039000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de1000-b5de2000 rw-p 0003a000 08:01 12324182   /usr/lib/libibus.so.1.0.0
b5de7000-b5de9000 r-xp 00000000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5de9000-b5dea000 r--p 00001000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5dea000-b5deb000 rw-p 00002000 08:01 12584487   /usr/lib/pango/1.6.0/modules/pango-basic-fc.so
b5deb000-b5dfc000 r-xp 00000000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfc000-b5dfd000 r--p 00011000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfd000-b5dfe000 rw-p 00012000 08:01 12327321   /usr/lib/gio/modules/libgioremote-volume-monitor.so
b5dfe000-b5e03000 r-xp 00000000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e03000-b5e04000 r--p 00004000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e04000-b5e05000 rw-p 00005000 08:01 12327767   /usr/lib/gtk-2.0/2.10.0/immodules/im-ibus.so
b5e05000-b5e06000 r--s 00000000 08:01 11796545   /var/cache/fontconfig/c05880de57d1f5e948fdfacc138775d9-le32d4.cache-3
b5e06000-b5e0c000 r--s 00000000 08:01 11796542   /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-le32d4.cache-3
b5e0c000-b5e0e000 r--s 00000000 08:01 11796543   /var/cache/fontconfig/99e8ed0e538f840c565b6ed5dad60d56-le32d4.cache-3
b5e0e000-b5e11000 r--s 00000000 08:01 11796552   /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-le32d4.cache-3
b5e11000-b5e13000 r--s 00000000 08:01 11803601   /var/cache/fontconfig/ea47318ec9849e1a71e80a5d69d13859-le32d4.cache-3
b5e13000-b5e14000 r--s 00000000 08:01 11803600   /var/cache/fontconfig/e3fa16a14183b06aa45b3e009278fd14-le32d4.cache-3
b5e14000-b5e15000 r--s 00000000 08:01 11796553   /var/cache/fontconfig/e7071f4a29fa870f4323321c154eba04-le32d4.cache-3
b5e15000-b5e17000 r--s 00000000 08:01 11804137   /var/cache/fontconfig/b5ea634b0fb353b8ea17632d1f9ef766-le32d4.cache-3
b5e17000-b5e1a000 r--s 00000000 08:01 11796539   /var/cache/fontconfig/6eb3985aa4124903f6ff08ba781cd364-le32d4.cache-3
b5e1a000-b5e1b000 r--s 00000000 08:01 11796535   /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-le32d4.cache-3
b5e1b000-b5e1c000 r--s 00000000 08:01 11796529   /var/cache/fontconfig/0d8c3b2ac0904cb8a57a757ad11a4a08-le32d4.cache-3
b5e1c000-b5e1d000 r--s 00000000 08:01 11796537   /var/cache/fontconfig/6a53c69dea097a2d716e069445527da8-le32d4.cache-3
b5e1d000-b5e21000 r--s 00000000 08:01 11796544   /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-le32d4.cache-3
b5e21000-b5e28000 r--s 00000000 08:01 11803865   /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-le32d4.cache-3
b5e28000-b5e33000 r--s 00000000 08:01 11796530   /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-le32d4.cache-3
b5e33000-b5e55000 r--s 00000000 08:01 11803842   /var/cache/fontconfig/365b55f210c0a22e9a19e35191240f32-le32d4.cache-3
b5e55000-b5e5d000 r--s 00000000 08:01 11796548   /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-le32d4.cache-3
b5e5d000-b5e87000 r-xp 00000000 08:01 12327750   /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so
b5e87000-b5e88000 r--p 00029000 08:01 12327750   /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xb5c71b70 (LWP 20640)]
0xb7fe2430 in __kernel_vsyscall ()
python
linux
wxpython
segmentation-fault
asked on Stack Overflow Aug 30, 2013 by ArmenB

1 Answer

4

First of all, wxPython 2.8 doesn't work with Python 3, so that part of your description doesn't make sense. There is a wxPython 2.9 Phoenix version that DOES work with Python 3, but it's kind of pre-beta right now.

You mention that you are updating the Grid widget via threads. If you are actually setting a value of cell directly (i.e. myGrid.SetCellValue()) from within a thread, then you're doing it incorrectly. wxPython has thread-safe methods that must be used to communicate from the thread to the GUI. Those are as follows:

  • wx.CallAfter
  • wx.CallLater
  • wx.PostEvent

You should read the following articles to see examples of how this works:

Those methods apply to ANY kind of interaction from a thread to the wxPython GUI, not just when updating the grid. For example, you might have a text or list control that you need to update. If so, you would still need to use one of the aforementioned methods to do so.

As mentioned by @multiphrenic, you should create a small runnable sample application that shows the issue you are having. You can read all about how to do that on the wxPython wiki.

answered on Stack Overflow Aug 30, 2013 by Mike Driscoll

User contributions licensed under CC BY-SA 3.0