pyvista / pyvistaqt

Qt support for PyVista
http://qtdocs.pyvista.org
MIT License
108 stars 19 forks source link

X Error of failed request: BadWindow (invalid Window parameter) #445

Open YuXHe15 opened 1 year ago

YuXHe15 commented 1 year ago

Hi I was trying the small example of pyvistaqt, namely

import pyvista as pv
from pyvistaqt import BackgroundPlotter
sphere = pv.Sphere()
plotter = BackgroundPlotter()
plotter.add_mesh(sphere)

while I got error:

X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 12 (X_ConfigureWindow) Resource id in failed request: 0x3 Serial number of failed request: 7 Current serial number in output stream: 8

After checking line by line I found it happends after creating the instance plotter of BackgoundPlotter()

My system is Ubuntu 22.04.2 LTS, using python 3.10

YuXHe15 commented 1 year ago

I did a little research around stackoverflow and one answer mentioned that it could happen when the window id passed is not correct, which can be found here: https://stackoverflow.com/questions/34704542/in-linux-get-window-class-raise-x-error-of-failed-request-badwindow-invalid I don't know if it would be helpful

NicolasCami commented 7 months ago

Hi there,

I get the exact same error output. I'm working with virtualenv. I tried with pyqt5, pyqt6, pyside6 (using os.environ["QT_API"]) and get the same error as soon as the BackgroundPlotter is instantiated.

I did several tests to understand if the issue is related to pyqt/pyside or qtpy or pyvista or pyvistaqt:

Here is an example that works. But if I uncomment QtInteractor or BackgroundPlotter lines I get the same error message.

import os
os.environ["QT_API"] = "pyside6"

from qtpy.QtWidgets import *
from pyvistaqt import QtInteractor, BackgroundPlotter

class MainWindow(QDialog):

    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.frame = QFrame()
        vlayout = QVBoxLayout()
        self.frame.setLayout(vlayout)

if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)

    # Produces X error: BadWindow
    #plotter = BackgroundPlotter(False, app=app)

    win = MainWindow()

    # Produces X error: BadWindow
    #interactor = QtInteractor(win)

    win.show()
    sys.exit(app.exec())

I wonder if it's related to my Qt installation, or Wayland. My config:

NicolasCami commented 6 months ago

Additional information: The issue only occurs on Wayland. Running the problematic example on X11 works. As a workaround, you can force Qt to use X11 instead of Wayland:

export QT_QPA_PLATFORM=xcb
python app.py
mscheltienne commented 1 month ago

Same problem with Ubuntu 24.04 LTS which defaults to Wayland.