致电glfw.init()之后,Badwindow在TKINTER中崩溃

发布于 2025-01-17 09:34:25 字数 1368 浏览 4 评论 0原文

我有以下代码,它可以在 Windows 上运行,但在具有 X11 的 Linux 上崩溃:

#! /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()

在 Linux/X11 上的消息框中单击“确定”后,程序崩溃并显示:

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

每次运行后地址都会有所不同,但是总体错误保持不变。
我能够将问题简化为调用 glfw.init() ,这会导致随后关闭 tkinter Windows 以使程序崩溃。但是,这不会发生在 Windows 系统上。

一些系统信息:

$ 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

为什么这个程序在我的系统上崩溃?
我该怎么做才能让它像在 Windows 上一样运行?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2025-01-24 09:34:25

我不是这方面的专家,但如果您只想拥有工作代码,则必须在 super().__init__() 之前调用 glfw.init() ,例如这个:

from tkinter import Tk
from tkinter.messagebox import showinfo

from glfw import init


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

    def __init__(self, *args, **kwargs):
        if not init():
            exit(2)
        super().__init__(*args, **kwargs)

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


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


if __name__ == '__main__':
    main()

我认为最好将 glfw.init() 放在 main 之前 MainWindow().mainloop() ,但我想为了表明我认为问题直接出在super().__ini__()

我没有测试 glfw 的任何功能,我只是检查了这个,因为 有关 SO 的其他问题

这里有一些您可以检查的链接,也许它们可以提供帮助:
togl
代码项目

I'm not an expert on this, but if you only want to have working code you have to call glfw.init() before super().__init__() like this:

from tkinter import Tk
from tkinter.messagebox import showinfo

from glfw import init


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

    def __init__(self, *args, **kwargs):
        if not init():
            exit(2)
        super().__init__(*args, **kwargs)

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


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


if __name__ == '__main__':
    main()

I think it is better to put the glfw.init() in main before MainWindow().mainloop(), but i wanted to make clear that i think the problem is directly in super().__ini__().

I did not tested any function of glfw, i only checked this because of other questions on SO

Here are some links you can check, maybe they can help:
togl
code project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文