Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   More Mac Issues - wxPython (http://www.programmingforums.org/showthread.php?t=14563)

Sane Nov 23rd, 2007 12:39 PM

More Mac Issues - wxPython
 
Has Anyone Tried wxPython For Max OSX?

I'm running Python 2.5 on Mac OSX 10.3.9.

I downloaded wxPython 2.8 - OSX - Unicode - 2.8.6.1 - Universal - Python 2.5.

When I run it, everything works fine. I can do lots of things like disable/enable widgets, select from a combo box, hide the window, select from the file menu, etc, etc...

However, when I try this code, I get a "Segmentation Fault" or "Bus Error". This does not happen on Windows. Any idea what's going on?

:

    def findBallot(self, event):
        self.checkBallotEntry(event)

        # Initiate Search List
        if self.lastImage == self.invalidImage:

            searchFor = event.GetString()
            matches = findClosest(searchFor, self.handler.ballotSeen)

            if matches:

                # hide stuff underneath
                self.ballotType.Hide()
                self.outputFile.Hide()
                self.selectFile.Hide()

                # remove the old search box
                if self.searchResults:
                    self.searchResults.Destroy()
                    self.searchResults = None

                matches.sort()
                # show the new search box
                self.searchResults = wx.ListBox(self.generalPanel, id=lazyID('search'), pos=wx.Point(75, 64), size=wx.Size(167, 75),
                    choices=[__LANG_SEARCH_RESULTS__%len(matches)] + matches, style=wx.LB_SINGLE)
                self.Bind(wx.EVT_LISTBOX, self.selectSearch, self.searchResults)

    def destroySearch(self):
        self.searchResults.Destroy()
        self.searchResults = None

        self.ballotType.Show()   
        self.outputFile.Show()
        self.selectFile.Show()

    def selectSearch(self, event):
        if event.GetSelection() != 0: # Can't pick the first result
            searchChoice = event.GetString()
            self.ballotList.SetValue(searchChoice)
            self.ballotList.SetFocusFromKbd()
            self.ballotList.SetInsertionPointEnd()
           
            # End Search List
            if self.searchResults:
                self.destroySearch()
           
            self.checkBallotEntry(None)


"findBallot" is called when a letter is typed. It toggles a search list if the entry is incorrect.

"destroySearch" destroys this search list once the entry is correct, or an item has been selected.

"selectSearch" is called when the user selects one of the search options.

The error happens after "selectSearch" is done. This makes little sense, because after "selectSearch" is done, no code is executed. The window remains idle, as a solitary cron task continues running every second afterwards. This task has always been executing, so this shouldn't be an issue. Nevertheless, the code is:

:

    def handleGlitch(self, event):
        # The win32api doesn't always tell us when the combobox's text changes, so check every second in case
        self.checkBallotEntry(None)
        event.Skip()


But "self.checkBallotEntry(None)" can't be the problem either, because it was succesfully called near the end of "selectSearch", which finished executing before the error occurred.

I can't show you any more code then this. I actually signed a non-disclosure agreement that stops me from even giving that much away... but whatever...

Edit : Probably important to note. I can still see the search list before the program stalls and crashes. This means it did not destroy the search list when it was supposed to. I think this is a good indicator of the error. What am I doing then that Mac OSX doesn't like? It was fine hiding/enabling other widgets. Maybe I'll look at the "destroy" attribute under Mac OSX. Do some testing there...

DaWei Nov 23rd, 2007 12:49 PM

Re: More Mac Issues - wxPython
 
I don't know anything about the Mac, but I'll make a couple of observations. Generally, a segmentation fault means that memory has been accessed when it is not valid to access that area of memory, for whatever reason.

A bus fault indicates that memory was accessed that can't be accessed. Usually, this is because the physical implementation of the memory is such that it can't be addressed on any given byte boundary, but must be accessed on, for example, 4-byte boundaries.

Maybe that will give you a clue. It certainly introduces platform dependencies that might result in a bug.

Sane Nov 23rd, 2007 1:01 PM

Re: More Mac Issues - wxPython
 
This problem is starting to look more defined now. Thanks.

I'm thinking it doesn't like me switching "self.searchResults" back and forth between a wxWidget listbox and a "None" type object, and then finally destroying it. It's most likely having memory allocation trouble with that. I will tweak the implementation, and see if that helps.

Sane Nov 23rd, 2007 1:16 PM

Re: More Mac Issues - wxPython
 
Yes! It works. Thanks, that was the exact issue. I made it create the listbox once, and toggle it on/off instead. It's actually better this way. Come to think of it, it's quite stupid to keep destroying/initiating the widget, especially when there's no good reason to... An obvious memory hazard.

Adios.


All times are GMT -5. The time now is 3:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC