Segmentation fault while using SetSize()
Freddy Spierenburg
freddy at dusktilldawn.nl
Tue Oct 2 01:49:50 PDT 2007
Hi,
I'm experiencing a strange segmentation fault while using
SetSize(). I'm using wxPython version 2.8.6.0. I've downloaded
the Debian-packages with the help from the Wiki. I'm also using
Python version 2.5.1 (r251:54863, Aug 17 2007, 00:51:07).
Anyway, the python code below causes the trouble:
self._panel.SetSize(
(wx.Size(self._panel.GetSize()[0] + 1, self._panel.GetSize()[1]))
)
After this statement python segfaults on me. I've pinpointed the
problem to the _wrap_Window_SetSize() function from the
wxPython/src/gtk/_core_wrap.cpp file and added some code like
below to it (only the non-indented code is my add-on):
{
PyThreadState* __tstate = wxPyBeginAllowThreads();
printf("a: %p %p\n",arg1,arg2);
{
wxSize freddy;
freddy = ((wxWindow const *)arg1)->GetSize();
printf("GetSize() = (%d,%d)\n",freddy.x,freddy.y);
}
(arg1)->SetSize((wxSize const &)*arg2);
printf("b\n");
wxPyEndAllowThreads(__tstate);
printf("c\n");
if (PyErr_Occurred()) SWIG_fail;
}
When running, this gives me:
/* I start the application. */
a: 0x8482598 0x86c4300
GetSize() = (684,520)
b
c
/* I press a button and dive into a new menu with buttons. */
a: 0x8482598 0x86c4300
GetSize() = (685,520)
b
c
/* I press another button, which causes me to go back to the
* first menu with buttons. */
a: 0x8482598 0x86c4300
GetSize() = (684,520)
Segmentation fault
$
There is a little more to it. The problem started when I changed the code
below:
def init_ui(self, parent):
# Load the panel from the resource file
# Now create the panel from the resource data
self._wxPanel = wx.GetApp().resource.LoadPanel(parent, self._resourcename)
# Show the panel
self._wxPanel.Show()
# Also return a reference to the panel
return self._wxPanel
into:
def load(self, parent):
# Load the panel from the resource file
# Now create the panel from the resource data
self._wxPanel = wx.GetApp().resource.LoadPanel(parent, self._resourcename)
# Hide the panel!
self._wxPanel.Hide()
def init_ui(self, parent):
# Show the panel
self._wxPanel.Show()
# Also return a reference to the panel
return self._wxPanel
Since the init_ui took to long (600ms) I thought to remove the
LoadPanel() to the start of the program. The init_ui() now only
has to show the stuff and the loading is done only one time in
advance. Maybe now some data is gone from memory, while pointers
are still pointing to the memory???
The strange part is that the GetSize() works on that same
pointer. It's only the SetSize() that causes the trouble.
I'm not sure if this is a bug or some misunderstanding on my part
about wx, so I'm asking this both on the development and user
mailing list. Please include my emailadres in any reply, since
I'm not member of both lists. Thanks for any help!
--
$ cat ~/.signature
Freddy Spierenburg <freddy at dusktilldawn.nl> http://freddy.snarl.nl/
GnuPG: 0x7941D1E1=C948 5851 26D2 FA5C 39F1 E588 6F17 FD5D 7941 D1E1
$ # Please read http://www.ietf.org/rfc/rfc2015.txt before complain!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20071002/3ba67ef5/attachment.pgp
More information about the wxpython-users
mailing list