https://bugs.kde.org/show_bug.cgi?id=527906

            Bug ID: 527906
           Summary: kwin_wayland crashes in RenderDevice::eglContext() on
                    any screenshot when there is no render device (virtual
                    backend, no /dev/dri)
    Classification: Plasma
           Product: kwin
      Version First 6.8.1
       Reported In:
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: crash
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 197719
  --> https://bugs.kde.org/attachment.cgi?id=197719&action=edit
Full gdb backtrace of kwin_wayland 6.8.1 (debug symbols via
debuginfod.archlinux.org)

SUMMARY
On the virtual backend with no GPU render node, any ScreenShot2 capture makes
kwin_wayland segfault. 
ScreenShotManager::takeScreenShot()
calls Compositor::self()->primaryDevice()->eglContext(), and primaryDevice() is
null there. 
CaptureScreen, CaptureArea and CaptureWorkspace all crash (CaptureWindow not
tested). 
The same unchecked call is in all three takeScreenShot() overloads

(screenshot.cpp lines 58, 125 and 199 on master today). 
With a render node passed in (--device /dev/dri) screenshots work.

I hit this running UI tests for a game in a container: headless kwin_wayland
--virtual, no GPU.

STEPS TO REPRODUCE
In a container with no /dev/dri, e.g. `docker run --rm -it archlinux:latest`:
1. pacman -Syu --noconfirm kwin spectacle dbus libcap
2. setcap -r /usr/bin/kwin_wayland   (only because Docker won't exec a binary
with file capabilities)
3. dbus-run-session bash
4. export XDG_RUNTIME_DIR=/tmp/xdg; mkdir -p -m 700 $XDG_RUNTIME_DIR
5. kwin_wayland --virtual --width 1280 --height 720 --socket wl0
--no-lockscreen &
6. WAYLAND_DISPLAY=wl0 QT_QPA_PLATFORM=wayland spectacle -b -n -f -o
/tmp/shot.png

OBSERVED RESULT
kwin_wayland segfaults (exit status 139). Spectacle exits with 255 and no
image. 

Terminal output from step 6:

kf.windowsystem: static bool KX11Extras::compositingActive() may only be used
on X11
The Wayland connection broke. Did the Wayland compositor die?
[1]+  Segmentation fault         (core dumped) kwin_wayland --virtual --width
1280 --height 720 --socket wl0 --no-lockscreen

EXPECTED RESULT
A screenshot, or a D-Bus error saying capture isn't available without a render
device, rather than a compositor crash.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux (container; host kernel 7.0.0-38-generic, Ubuntu)
KDE Plasma Version: 6.8.1 (kwin 6.8.1-2)
KDE Frameworks Version: 6.31.0
Qt Version: 6.12.0
Graphics Platform: Wayland, virtual backend, no render node (Mesa 26.2.5
installed)

ADDITIONAL INFORMATION
Backtrace (debug symbols from debuginfod.archlinux.org):

Thread 1 "kwin_wayland" received signal SIGSEGV, Segmentation fault.
#0  KWin::RenderDevice::eglContext (this=this@entry=0x0) at
src/core/renderdevice.cpp:143
#1  KWin::ScreenShotManager::takeScreenShot (this=<optimized out>,
screen=0x5e2bf2077510, flags=..., pidToHide=...) at
src/plugins/screenshot/screenshot.cpp:58
#2  KWin::ScreenShotDBusInterface2::takeScreenShot (screen=0x5e2bf2077510,
flags=..., sink=0x716a6c013850, pid=..., this=<optimized out>) at
src/plugins/screenshot/screenshotdbusinterface2.cpp:435
#3  KWin::ScreenShotDBusInterface2::CaptureScreen
(this=this@entry=0x5e2bf21ffb40, name=..., options=..., pipe=...) at
src/plugins/screenshot/screenshotdbusinterface2.cpp:330
#4  ScreenShot2Adaptor::CaptureScreen (this=<optimized out>, name=...,
options=..., pipe=...) at
build/src/plugins/screenshot/screenshot2adaptor.cpp:69
#5  ScreenShot2Adaptor::qt_static_metacall (...) at
build/src/plugins/screenshot/moc_screenshot2adaptor.cpp
#6  ScreenShot2Adaptor::qt_metacall (...) at
build/src/plugins/screenshot/moc_screenshot2adaptor.cpp:225
#7  QDBusConnectionPrivate::deliverCall (...) at
qtbase/src/dbus/qdbusintegrator.cpp
(full trace attached: backtrace.txt)

KWin's startup log in this setup. Despite the last line, kwin_wayland keeps
running and accepting clients (in our tests for many
minutes) until the screenshot request crashes it:

Failed to gain real time thread priority (See CAP_SYS_NICE in the
capabilities(7) man page). error: Operation not permitted
Accepting client connections on sockets: QList("wl0")
kwin_core: Failed to open drm node /dev/dri/renderD128: No such file or
directory
kwin_core: Found no render device!
kwin_core: Failed to load cursor theme "default"
kwin_core: Failed to load cursor theme "default"
kwin_screencast: Failed to connect PipeWire context
kwin_core: Found no render device!
kwin_core: The used windowing system requires compositing
kwin_core: We are going to quit KWin now as it is broken
The CaptureArea path gives the same frame #0 from screenshot.cpp:125. It
crashes the same way with KWIN_COMPOSE=O2 and KWIN_COMPOSE=Q.

Possibly related but a different cause: bug 524840 (null EglContext after
prePaint, on a real GPU, fixed in 6.7.6). Here the RenderDevice
itself is null.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to