"wxPython in Action" example fails with bus error on OS X

Greetings,

Working my way through the book “wxPython in Action”, I’ve been running the examples and hacking changes to them to get a feel for wxPython.

Well, while working my way through chapter 6, I hit a wall working with the example1.py script (attached for informational purposes). I’m running the examples from a terminal, in the fashion of: “pythonw example1.py”. When I ran this paticular example script, it would take some time and then exit with a bus error. It then raised a pop window that said “The application Python quit unexpectedly.” When I clicked to get details, the following info was made available (pasting only the top details along with the top line of the stack trace. I can provide the whole stack trace if necessary):

Date/Time: 2006-06-08 15:38:37.344 -0700
OS Version: 10.4.6 (Build 8I127)
Report Version: 4

Command: Python
Path: /Users/testmonkey/peeps/thirdparty/dist/osx/Library/Framework/Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/Python

Parent: bash [244]

Version: 2.4a0 (2.4alpha1)

PID: 1039
Thread: 0

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 gdi.so 0x0263a108 _wrap_new_BufferedDC + 872 (dc.h:436)

So I dug into the example1.py code and discovered that the problem was in the following method off of the SketchWindow class:

def InitBuffer(self):

    size = self.GetClientSize()
    self.buffer = wx.EmptyBitmap(size.width, size.height)
    dc = wx.BufferedDC(None, self.buffer)
    dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
    dc.Clear()
    self.DrawLines(dc)
    self.reInitBuffer = False

I dropped the script into pdb and stepped through this method, discovering that the size object had a value of 0 for both the width and height attributes. Looking at the GetClientSize method from the api docs, it read: This gets the size of the window’s ‘client area’ in pixels. This sketch window class is a subclass of wx.Window and it’s parent was a frame when the script is run. If I understand this GetClientSize call correctly, it should be retrieving the size attributes from the parent. But for some reason, the GetClientSize method is returning 0’s.

After doing some more digging, I made the following changes to the InitBuffer method for testing:
[ ``](http://www.wxpython.org/docs/api/wx.Window-class.html#GetClientSize) def InitBuffer(self):
z = self.GetParent()
size = z.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height
)
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DrawLines(dc)
self.reInitBuffer = False

I ran the example1.py script again and it worked as expected.

My setup is OS X box (running 10.4.6). I’ve built my own version of python 2.4.3 (as a framework) and I’m using wxPython 2.6.3.2.

Now my question is whether I’m the only one running into this issue? If so, then I’ve got something funky going on with my build of python/wxpython and I’ve got to figure out what I’m doing wrong. I’m just trying to get a sanity check here.

TIA
Johnnie

example1.py (3.16 KB)

johnnie pittman wrote:

Now my question is whether I'm the only one running into this issue? If so, then I've got something funky going on with my build of python/wxpython and I've got to figure out what I'm doing wrong.

Nothing wrong. It is possible for the client size to be zero when the window is first created, and it hasn't yet been resized by the parent. But as you've discovered this uncovers the problem that the Mac has with bitmaps with a zero dimension. See the errata page for one way to protect against this.

http://wxpython.org/bookerrata.php

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks Robin. I hit every other single source of information besides the errata page. It’s first on my list next time.

···

On 6/8/06, Robin Dunn < robin@alldunn.com> wrote:

johnnie pittman wrote:

Now my question is whether I’m the only one running into this issue? If

so, then I’ve got something funky going on with my build of
python/wxpython and I’ve got to figure out what I’m doing wrong.

Nothing wrong. It is possible for the client size to be zero when the

window is first created, and it hasn’t yet been resized by the parent.
But as you’ve discovered this uncovers the problem that the Mac has with
bitmaps with a zero dimension. See the errata page for one way to
protect against this.

http://wxpython.org/bookerrata.php


Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org