segfault in wxPython "showcase"

There may be some additional things that can be done without too much hassle. I'll think some more about it and see if anything turns up.

···

On 1/25/11 11:11 AM, Christopher Barker wrote:

Robin -- is "Phoenix" going to handle this sort of thing
differently/better? -- it seems maybe the wrappers should be doing more
checking, rather than counting on C++ assertions.

--
Robin Dunn
Software Craftsman

You'll need to install python-dbg, the -dbg versions of the wx packages, and also for any other extension module packages that you need for your project. Then you should run python-dbg instead of python.

Hmmm... I just tried the above and it looks like python-dbg is not altering the sys.path like it should to be able to find the debug version of the extension modules, so either I've got something wrong on my box, there's a bug in the Ubuntu python-deb package, or it has changed and doesn't work the way I expect any longer...

···

On 1/25/11 3:17 PM, Micah Nordland wrote:

on ubuntu, what package are those assertions in?

--
Robin Dunn
Software Craftsman

Le 25/01/2011 19:24, Robin Dunn a �crit :

[...]

What it's not able to do as much of is to ensure that things are used correctly. wxWidgets does have a lot of assertion and similar statements that check for those kinds of things, but if you are on linux and are using wx packages from your distro provider then odds are that they have not turned on the runtime assertions when the wx libraries were built. You can check for sure by looking at wx.PlatformInfo. Here is the one from the Ubuntu packages:

>>> import wx
>>> wx.PlatformInfo
('__WXGTK__', 'wxGTK', 'unicode', 'gtk2', 'wx-assertions-off', 'SWIG-1.3.29')
>>>

And here is one built in my current wxPython workspace:

>>> import wx
>>> wx.PlatformInfo
('__WXGTK__', 'wxGTK', 'unicode', 'gtk2', 'wx-assertions-on', 'SWIG-1.3.29')
>>>

I tried to build a wxPython debugging version on my Slackware Linux. I carefully followed what's on http://www.wxpython.org/BUILD-2.8.html and it seemed to work:

/home/essais/Wx_Tk_Challenge$ python
Python 2.6.4 (r264:75706, Dec 5 2009, 21:18:28)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.PlatformInfo
('__WXGTK__', 'wxGTK', 'unicode', 'gtk2', 'wx-assertions-on', 'SWIG-1.3.29')
>>>

When the assertions are turned on then wxPython is able to catch them and raise them as Python exceptions that will usually help you figure out what you did wrong. Otherwise the wx code will usually just continue on doing the thing that the assertion would have warned is a bad thing to do, which can lead to a segfault. If you are using Linux as your primary development system then I strongly recommend that while in development and testing phases you either use the debug wx and wxPython packages if yoiur distro provides them, or build your own set of wxWidgets and wxPython binaries and adjust your PYTHONPATH and LD_LIBRARY_PATH to use that copy while in develop/test mode.

I then tried to see those wx-assertions in action:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation

None appeared. What am I doing wrong?

···

--
jmp

I don't know. Is it possible that a different Python or wxPython is being used the 2nd time? (Possible PATH or PYTHONPATH differences, etc.)

Here is what I get from the original sample:

Loading Images:
  -- /media/sf_robind/Desktop/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
  -- /media/sf_robind/Desktop/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
  -- /media/sf_robind/Desktop/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Traceback (most recent call last):
   File "wxtk_challenge_1.py", line 224, in <module>
     frame = AppFrame()
   File "wxtk_challenge_1.py", line 208, in __init__
     self.listWidget.showDirectory(sys.prefix)
   File "wxtk_challenge_1.py", line 153, in showDirectory
     index = self.InsertImageStringItem(idx, name, imageIdx)
   File "/projects/wx/2.8/wxPython/wx/_controls.py", line 4761, in InsertImageStringItem
     return _controls_.ListCtrl_InsertImageStringItem(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "node" failed at ../wx/src/generic/listctrl.cpp(1329) in SetItem(): invalid column index in SetItem

···

On 1/26/11 7:00 AM, Jean-Marie Pacquet wrote:

Le 25/01/2011 19:24, Robin Dunn a �crit :

I tried to build a wxPython debugging version on my Slackware Linux. I
carefully followed what's on http://www.wxpython.org/BUILD-2.8.html and
it seemed to work:

/home/essais/Wx_Tk_Challenge$ python
Python 2.6.4 (r264:75706, Dec 5 2009, 21:18:28)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.PlatformInfo
('__WXGTK__', 'wxGTK', 'unicode', 'gtk2', 'wx-assertions-on',
'SWIG-1.3.29')
>>>

When the assertions are turned on then wxPython is able to catch them
and raise them as Python exceptions that will usually help you figure
out what you did wrong. Otherwise the wx code will usually just
continue on doing the thing that the assertion would have warned is a
bad thing to do, which can lead to a segfault. If you are using Linux
as your primary development system then I strongly recommend that
while in development and testing phases you either use the debug wx
and wxPython packages if yoiur distro provides them, or build your own
set of wxWidgets and wxPython binaries and adjust your PYTHONPATH and
LD_LIBRARY_PATH to use that copy while in develop/test mode.

I then tried to see those wx-assertions in action:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
-- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation

None appeared. What am I doing wrong?

--
Robin Dunn
Software Craftsman

Le 26/01/2011 21:01, Robin Dunn a �crit :

···

On 1/26/11 7:00 AM, Jean-Marie Pacquet wrote:

Le 25/01/2011 19:24, Robin Dunn a �crit :

I tried to build a wxPython debugging version on my Slackware Linux. I
carefully followed what's on http://www.wxpython.org/BUILD-2.8.html and
it seemed to work:

/home/essais/Wx_Tk_Challenge$ python
Python 2.6.4 (r264:75706, Dec 5 2009, 21:18:28)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.PlatformInfo
('__WXGTK__', 'wxGTK', 'unicode', 'gtk2', 'wx-assertions-on',
'SWIG-1.3.29')
>>>

When the assertions are turned on then wxPython is able to catch them
and raise them as Python exceptions that will usually help you figure
out what you did wrong. Otherwise the wx code will usually just
continue on doing the thing that the assertion would have warned is a
bad thing to do, which can lead to a segfault. If you are using Linux
as your primary development system then I strongly recommend that
while in development and testing phases you either use the debug wx
and wxPython packages if yoiur distro provides them, or build your own
set of wxWidgets and wxPython binaries and adjust your PYTHONPATH and
LD_LIBRARY_PATH to use that copy while in develop/test mode.

I then tried to see those wx-assertions in action:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
-- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation

None appeared. What am I doing wrong?

I don't know. Is it possible that a different Python or wxPython is being used the 2nd time? (Possible PATH or PYTHONPATH differences, etc.)

Thanks for your answer.

No it's the same Python and the same wxPython in both cases. wxPython has been built for debug but it is the standard Python 2.6.4 provided with this Slackware release: do I need a debugging version of Python?
--
jmp

No. It helps if you are actually going to be using a C debugger, but on a linux system it is not be needed for running debug build extension modules.

···

On 1/26/11 1:26 PM, Jean-Marie Pacquet wrote:

I then tried to see those wx-assertions in action:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
-- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation

None appeared. What am I doing wrong?

I don't know. Is it possible that a different Python or wxPython is
being used the 2nd time? (Possible PATH or PYTHONPATH differences, etc.)

Thanks for your answer.

No it's the same Python and the same wxPython in both cases. wxPython
has been built for debug but it is the standard Python 2.6.4 provided
with this Slackware release: do I need a debugging version of Python?

--
Robin Dunn
Software Craftsman

Le 26/01/2011 21:01, Robin Dunn a �crit :

I don't know. Is it possible that a different Python or wxPython is being used the 2nd time? (Possible PATH or PYTHONPATH differences, etc.)

Just to be sure, I removed the wxPython standard package so that I only have one wxPython, the one I built for debug:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Traceback (most recent call last):
   File "wxtk_challenge_1.py", line 7, in <module>
     import wx
ImportError: No module named wx
/home/essais/Wx_Tk_Challenge$ export LD_LIBRARY_PATH=/opt/wx/2.8/lib
/home/essais/Wx_Tk_Challenge$ export PATH=$PATH:/opt/wx/2.8/bin
/home/essais/Wx_Tk_Challenge$ export WXDIR=/home/essais/wxPython-src-2.8.11.0
/home/essais/Wx_Tk_Challenge$ export PYTHONPATH=$WXDIR/wxPython
/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
  -- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation
/home/essais/Wx_Tk_Challenge$

Still no assertions!
Any idea for what I should look at?

···

--
jmp

Le 26/01/2011 21:01, Robin Dunn a �crit :

I don't know. Is it possible that a different Python or wxPython is
being used the 2nd time? (Possible PATH or PYTHONPATH differences, etc.)

Just to be sure, I removed the wxPython standard package so that I only
have one wxPython, the one I built for debug:

/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Traceback (most recent call last):
File "wxtk_challenge_1.py", line 7, in <module>
import wx
ImportError: No module named wx
/home/essais/Wx_Tk_Challenge$ export LD_LIBRARY_PATH=/opt/wx/2.8/lib
/home/essais/Wx_Tk_Challenge$ export PATH=$PATH:/opt/wx/2.8/bin
/home/essais/Wx_Tk_Challenge$ export
WXDIR=/home/essais/wxPython-src-2.8.11.0
/home/essais/Wx_Tk_Challenge$ export PYTHONPATH=$WXDIR/wxPython
/home/essais/Wx_Tk_Challenge$ python wxtk_challenge_1.py
Loading Images:
-- /home/essais/Wx_Tk_Challenge/Bitmaps/file.bmp, file.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/folder.bmp, folder.bmp
-- /home/essais/Wx_Tk_Challenge/Bitmaps/link.bmp, link.bmp
imageMap.keys -> ['folder', 'link', 'file']
Erreur de segmentation
/home/essais/Wx_Tk_Challenge$

Still no assertions!
Any idea for what I should look at?

The only thing I can think of is to ensure that you indeed have the assertions turned on by trying to trigger one. If that works then I guess for the challenge code is that there is some other problem that you are running into before it hits the assertion that I'm seeing when I run the sample. Here is a simple way to trigger a different assertion:

  Python 2.6.4 (r264:75706, Feb 4 2010, 23:47:47)
  [GCC 4.4.1] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import wx
  >>> wx.version()
  '2.8.11.0 (gtk2-unicode)'
  >>> app = wx.App(False)
  >>> w = wx.Window(None)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "wx/_core.py", line 8438, in __init__
      _core_.Window_swiginit(self,_core_.new_Window(*args, **kwargs)) wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at ../wx/src/gtk/window.cpp(2415) in Create(): wxWindowGTK creation failed

···

On 1/27/11 1:22 AM, Jean-Marie Pacquet wrote:
  >>>

--
Robin Dunn
Software Craftsman

Le 28/01/2011 20:14, Robin Dunn a �crit :

The only thing I can think of is to ensure that you indeed have the assertions turned on by trying to trigger one. If that works then I guess for the challenge code is that there is some other problem that you are running into before it hits the assertion that I'm seeing when I run the sample. Here is a simple way to trigger a different assertion:

Python 2.6.4 (r264:75706, Feb 4 2010, 23:47:47)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'2.8.11.0 (gtk2-unicode)'
>>> app = wx.App(False)
>>> w = wx.Window(None)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "wx/_core.py", line 8438, in __init__
     _core_.Window_swiginit(self,_core_.new_Window(*args, **kwargs)) wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at ../wx/src/gtk/window.cpp(2415) in Create(): wxWindowGTK creation failed
>>>

OK, I get this one:

/home/essais/Wx_Tk_Challenge_1$ python
Python 2.6.4 (r264:75706, Dec 5 2009, 21:18:28)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'2.8.11.0 (gtk2-unicode)'
>>> app = wx.App(False)
>>> w = wx.Window(None)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/home/essais/wxPython-src-2.8.11.0/wxPython/wx/_core.py", line 8438, in __init__
     _core_.Window_swiginit(self,_core_.new_Window(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at ../src/gtk/window.cpp(2415) in Create(): wxWindowGTK creation failed
>>>

I tried yesterday to build a small example (getassert.py) from the Wx_Tk challenge that triggers the same kind of segfault. It does produce a segfault but there is no assert error before:

/home/essais/Wx_Tk_Challenge_1$ python getassert.py
Erreur de segmentation
/home/essais/Wx_Tk_Challenge_1$ gdb python
GNU gdb (GDB) 7.1
[...]
(gdb) run getassert.py
Starting program: /usr/bin/python getassert.py
[Thread debugging using libthread_db enabled]
Traceback (most recent call last):
   File "/usr/share/gdb/auto-load/usr/lib/libgobject-2.0.so.0.2200.5-gdb.py", line 9, in <module>
     from gobject import register
   File "/usr/share/glib-2.0/gdb/gobject.py", line 3, in <module>
     import gdb.backtrace
ImportError: No module named backtrace

Program received signal SIGSEGV, Segmentation fault.
0xb72a7b51 in wxListMainWindow::InsertItem (this=0x83ea6f0, item=...)
     at ../src/generic/listctrl.cpp:4766
4766 wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
(gdb) bt
#0 0xb72a7b51 in wxListMainWindow::InsertItem (this=0x83ea6f0, item=...)
     at ../src/generic/listctrl.cpp:4766
#1 0xb72aa1f0 in wxGenericListCtrl::InsertItem (this=0x83e98d8, info=...)
     at ../src/generic/listctrl.cpp:5578
#2 0xb72aa377 in wxGenericListCtrl::InsertItem (this=0x83e98d8, index=0,
     label=..., imageIndex=-1) at ../src/generic/listctrl.cpp:5607
#3 0xb5d55ad5 in _wrap_ListCtrl_InsertStringItem (args=0x82ee644, kwargs=
     0xb7bcce84) at src/gtk/_controls_wrap.cpp:31618
#4 0xb7ec71ba in PyCFunction_Call () from /usr/lib/libpython2.6.so.1.0
[...]

I think I will have to live with that and continue to use gdb if I ever get a segfault without any assert.
Thanks for your time

getassert.py (423 Bytes)

···

--
jmp