beeware / bugjar

A interactive graphical debugger for Python code.
BSD 3-Clause "New" or "Revised" License
249 stars 31 forks source link

GUI crashes with freePtr when stepping through code on Windows 8 #4

Open khoobks opened 11 years ago

khoobks commented 11 years ago

When playing with testing bugjar on Windows 8 I discovered that the UI component will consistenly crash with the following error on the console.

TclStackFree: incorrect freePtr. Call out of sequence?

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Based on this link, it seems that this error is caused by more than one thread accessing the tk event loop.

My hypothesis is that the Debugger is invoking callbacks such as MainWindow.on_stack and MainWindow.on_line from the non tk event thread.

Below is an attempt to rectify this situation using the python Queue object.

class MainWindow(object):
    def __init__(self, root, debugger):

        # <snip>------------

        self.queue = Queue.Queue()
        self.root.after(200, self.debugger_update)

        debugger.start()

    def debugger_update(self):
        try:
            while 1:
                func_name, args = self.queue.get_nowait()
                handler = getattr(self, func_name)
                handler(*args)
        except Queue.Empty:
            pass
        self.root.after(100, self.debugger_update)

    # <snip>------------

    def on_stack(self, stack):
        self.queue.put(('_on_stack', (stack,),))

    def _on_stack(self, stack):
        # <snip>------------

Using the above setup, I have found that I am able to step through the code without encountering the same freePtr issue.