Thursday, 31 March 2022

BadWindow crash in tkinter after calling glfw.init()

I have the following code, which works on Windows, but crashes on Linux with X11:

#! /usr/bin/env python3
"""Tkinter crashes on X11 when popup windows
are closed after calling glfw.init()
"""

from sys import exit

from tkinter import Tk
from tkinter.messagebox import showinfo

from glfw import init


class MainWindow(Tk):
    """Main window."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if not init():
            exit(2)

        showinfo('Close me', 'I dare you')


def main():
    """Run the script."""

    MainWindow().mainloop()


if __name__ == '__main__':
    main()

After clicking OK in the message box on Linux/X11, the program crashes with:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  15 (X_QueryTree)
  Resource id in failed request:  0x4c0000a
  Serial number of failed request:  778
  Current serial number in output stream:  778

The addresses vary after each run, but the overall error stays the same.
I was able to reduce the problem to the call of glfw.init() which results in subsequent closing of tkinter Windows to crash the program. However, this does not happen on Windows systems.

Some system info:

$ uname -r
5.16.16-arch1-1
$ pacman -Q xorg-server
xorg-server 21.1.3-6
$ echo $XDG_SESSION_TYPE
x11
$ pacman -Q glfw python-glfw
glfw-x11 3.3.6-1
python-glfw 2.1.0-2

Why is this program crashing on my system?
What can I do to make it run just like on windows?



from BadWindow crash in tkinter after calling glfw.init()

No comments:

Post a Comment