Bug 489632 - Kwin crashes in KWin::Window::setMoveResizeOutput() after disconnecting display
Summary: Kwin crashes in KWin::Window::setMoveResizeOutput() after disconnecting display
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: generic-crash (other bugs)
Version First Reported In: 6.1.1
Platform: NixOS Linux
: NOR crash
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: multiscreen, wayland-only
Depends on:
Blocks:
 
Reported: 2024-07-02 19:34 UTC by akhtaboot
Modified: 2025-09-29 23:10 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.1.4
Sentry Crash Report: https://crash-reports.kde.org/organizations/kde/issues/36638


Attachments
coredump-backtrace (40.07 KB, text/plain)
2024-07-02 19:34 UTC, akhtaboot
Details
another backtrace (43.58 KB, text/plain)
2024-07-02 19:38 UTC, akhtaboot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description akhtaboot 2024-07-02 19:34:09 UTC
Created attachment 171305 [details]
coredump-backtrace

***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***

SUMMARY
The crash happens after disconnecting a laptop from an external display (connected via a docking station), this only started happening on 6.1 I think


Might be related to https://bugs.kde.org/show_bug.cgi?id=489414

STEPS TO REPRODUCE
1. Disconnect the display

OBSERVED RESULT
Crash! Sometimes it might result in all windows crashing and kwin restarting

EXPECTED RESULT
No crash!

SOFTWARE/OS VERSIONS
Operating System: NixOS 24.11
KDE Plasma Version: 6.1.1
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.2
Kernel Version: 6.6.36 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 7840U w/ Radeon 780M Graphics
Memory: 27,2 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Comment 1 akhtaboot 2024-07-02 19:38:59 UTC
Created attachment 171306 [details]
another backtrace
Comment 3 akhtaboot 2024-07-02 20:28:33 UTC
(In reply to Zamundaaa from comment #2)
> Please get a complete backtrace following
> https://community.kde.org/Guidelines_and_HOWTOs/Debugging/
> How_to_create_useful_crash_reports#Retrieving_a_backtrace_using_coredumpctl

This is the backtrace I get with `coredumpctl gdb`
I am figuring out how to get debug symbols on NixOS 

```
(gdb) backtrace
#0  0x00007fe9f39d9729 in QMetaObjectPrivate::disconnect(QObject const*, int, QMetaObject const*, QObject const*, int, void**, QMetaObjectPrivate::DisconnectType) ()
   from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#1  0x00007fe9f39da05a in QObject::disconnectImpl(QObject const*, void**, QObject const*, void**, QMetaObject const*) ()
   from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#2  0x00007fe9f6c724d9 in KWin::Window::setMoveResizeOutput(KWin::Output*) () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#3  0x00007fe9f6c727bd in KWin::Window::setMoveResizeGeometry(QRectF const&) () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#4  0x00007fe9f6cb921a in KWin::XdgSurfaceWindow::handleNextWindowGeometry() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#5  0x00007fe9f6cb93ce in KWin::XdgSurfaceWindow::handleCommit() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#6  0x00007fe9f39e4ec0 in void doActivate<false>(QObject*, int, void**) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#7  0x00007fe9f6e508a8 in KWin::SurfaceInterfacePrivate::applyState(KWin::SurfaceState*) () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#8  0x00007fe9f6e7f252 in KWin::Transaction::apply() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#9  0x00007fe9f6e7eddc in KWin::Transaction::tryApply() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#10 0x00007fe9f6e80d03 in KWin::Transaction::commit() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#11 0x00007fe9f6e4f170 in KWin::SurfaceInterfacePrivate::surface_commit(QtWaylandServer::wl_surface::Resource*) ()
   from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#12 0x00007fe9f2a44052 in ffi_call_unix64 () from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#13 0x00007fe9f2a41ee5 in ffi_call_int () from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#14 0x00007fe9f2a42ad8 in ffi_call () from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#15 0x00007fe9f7503841 in wl_closure_invoke () from /nix/store/p70yz972riakl5l0k7nzakyybi5r8481-wayland-1.22.0/lib/libwayland-server.so.0
#16 0x00007fe9f74fec4b in wl_client_connection_data () from /nix/store/p70yz972riakl5l0k7nzakyybi5r8481-wayland-1.22.0/lib/libwayland-server.so.0
#17 0x00007fe9f75018f2 in wl_event_loop_dispatch () from /nix/store/p70yz972riakl5l0k7nzakyybi5r8481-wayland-1.22.0/lib/libwayland-server.so.0
#18 0x00007fe9f6ddfa52 in KWin::Display::dispatchEvents() () from /nix/store/ybw0sy554h8raglxmbm5wkj3arxc1rwg-kwin-6.1.0/lib/libkwin.so.6
#19 0x00007fe9f39e4ec0 in void doActivate<false>(QObject*, int, void**) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#20 0x00007fe9f39f1eef in QSocketNotifier::activated(QSocketDescriptor, QSocketNotifier::Type, QSocketNotifier::QPrivateSignal) ()
   from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#21 0x00007fe9f39f26a5 in QSocketNotifier::event(QEvent*) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#22 0x00007fe9f4b94d21 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Widgets.so.6
#23 0x00007fe9f3981d60 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#24 0x00007fe9f3b2f4de in QEventDispatcherUNIXPrivate::activateSocketNotifiers() () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#25 0x00007fe9f3b2fb81 in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#26 0x00007fe9f46e260d in QUnixEventDispatcherQPA::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Gui.so.6
#27 0x00007fe9f398eaf3 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#28 0x00007fe9f398ac86 in QCoreApplication::exec() () from /nix/store/vzhlcx5vzicjkbb9i37ryslaa6s3gb57-qtbase-6.7.1/lib/libQt6Core.so.6
#29 0x00000000004450d5 in main ()
(gdb) 
```
Comment 4 akhtaboot 2024-07-03 13:14:07 UTC
after getting debug symbols in:

```
Core was generated by `/run/wrappers/bin/kwin_wayland --wayland-fd 7 --socket wayland-0 --xwayland-fd'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007eff057d9609 in QMetaObjectPrivate::disconnect(QObject const*, int, QMetaObject const*, QObject const*, int, void**, QMetaObjectPrivate::DisconnectType) ()
   from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
[Current thread is 1 (Thread 0x7efeff43db00 (LWP 2580))]
(gdb) backtrace
#0  0x00007eff057d9609 in QMetaObjectPrivate::disconnect(QObject const*, int, QMetaObject const*, QObject const*, int, void**, QMetaObjectPrivate::DisconnectType) ()
   from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#1  0x00007eff057d9f3a in QObject::disconnectImpl(QObject const*, void**, QObject const*, void**, QMetaObject const*) ()
   from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#2  0x00007eff08c73ca9 in QObject::disconnect<void (KWin::Output::*)(), void (KWin::Window::*)()> (
    slot=(void (KWin::Window::*)(KWin::Window * const)) 0x7eff08c73a80 <KWin::Window::updatePreferredBufferScale()>, receiver=0x64ee7e0, 
    signal=(void (KWin::Output::*)(KWin::Output * const)) 0x7eff08a1fbb0 <KWin::Output::scaleChanged()>, sender=<optimized out>)
    at /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/include/QtCore/qobject.h:306
#3  KWin::Window::setMoveResizeOutput (this=0x64ee7e0, output=0x5c928e0)
    at /build/kwin-6.1.1.2/src/window.cpp:3322
#4  0x00007eff08c73f8d in KWin::Window::setMoveResizeGeometry (this=0x64ee7e0, geo=...)
    at /build/kwin-6.1.1.2/src/window.cpp:3307
#5  0x00007eff08cbab0a in KWin::XdgSurfaceWindow::handleNextWindowGeometry (
    this=this@entry=0x64ee7e0) at /build/kwin-6.1.1.2/src/xdgshellwindow.cpp:233
#6  0x00007eff08cbacbe in KWin::XdgSurfaceWindow::handleCommit (this=0x64ee7e0)
    at /build/kwin-6.1.1.2/src/xdgshellwindow.cpp:154
#7  0x00007eff057e4da0 in void doActivate<false>(QObject*, int, void**) ()
   from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#8  0x00007eff08e52028 in KWin::SurfaceInterfacePrivate::applyState (this=0x501a940, 
    next=0x50780c0) at /build/kwin-6.1.1.2/src/wayland/surface.cpp:729
#9  0x00007eff08e809d2 in KWin::Transaction::apply (this=0x6224190)
    at /build/kwin-6.1.1.2/src/wayland/transaction.cpp:229
#10 0x00007eff08e8055c in KWin::Transaction::tryApply (this=this@entry=0x6224190)
    at /build/kwin-6.1.1.2/src/wayland/transaction.cpp:262
#11 0x00007eff08e82483 in KWin::Transaction::commit (this=this@entry=0x6224190)
    at /build/kwin-6.1.1.2/src/wayland/transaction.cpp:296
#12 0x00007eff08e508f0 in KWin::SurfaceInterfacePrivate::surface_commit (this=0x501a940, 
    resource=<optimized out>) at /build/kwin-6.1.1.2/src/wayland/surface.cpp:379
#13 0x00007eff04a0c052 in ffi_call_unix64 ()
   from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#14 0x00007eff04a09ee5 in ffi_call_int ()
   from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#15 0x00007eff04a0aad8 in ffi_call ()
   from /nix/store/nj9g42fdsm8l2z43kfcahch3px2q209a-libffi-3.4.6/lib/libffi.so.8
#16 0x00007eff094ca841 in wl_closure_invoke (closure=0x61a1600, flags=<optimized out>, 
    target=<optimized out>, opcode=6, data=<optimized out>) at ../src/connection.c:1025
#17 0x00007eff094c5c4b in wl_client_connection_data (fd=<optimized out>, 
    mask=<optimized out>, data=0x5ef0420) at ../src/wayland-server.c:438
#18 0x00007eff094c88f2 in wl_event_loop_dispatch (loop=0x4d6e960, timeout=<optimized out>)
    at ../src/event-loop.c:1034
#19 0x00007eff08de1122 in KWin::Display::dispatchEvents (this=<optimized out>)
    at /build/kwin-6.1.1.2/src/wayland/display.cpp:118
#20 0x00007eff057e4da0 in void doActivate<false>(QObject*, int, void**) ()
   from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
--Type <RET> for more, q to quit, c to continue without paging--
e, QSocketNotifier::QPrivateSignal) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#22 0x00007eff057f2585 in QSocketNotifier::event(QEvent*) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#23 0x00007eff06b94d21 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Widgets.so.6
#24 0x00007eff05781c10 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#25 0x00007eff0592f4ce in QEventDispatcherUNIXPrivate::activateSocketNotifiers() () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#26 0x00007eff0592fb71 in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#27 0x00007eff064e27ed in QUnixEventDispatcherQPA::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Gui.so.6
#28 0x00007eff0578e9d3 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#29 0x00007eff0578ab66 in QCoreApplication::exec() () from /nix/store/4qrmlniaj7x49sl6i1w4c2sjjdx00ghh-qtbase-6.7.2/lib/libQt6Core.so.6
#30 0x00000000004451b5 in main (argc=<optimized out>, argv=<optimized out>) at /build/kwin-6.1.1.2/src/main_wayland.cpp:642
```
Comment 5 Zamundaaa 2024-07-03 14:56:25 UTC
Hmm, the move resize output is most likely a dangling pointer.
Comment 6 Louis Moureaux 2024-07-12 17:33:19 UTC
Can reproduce 100% of the time when unplugging my USB-C monitor, with the same stack trace.

Operating System: KDE neon 6.0
KDE Plasma Version: 6.1.2
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.0
Kernel Version: 6.5.0-41-generic (64-bit)
Graphics Platform: Wayland
Processors: 8 × Intel® Core™ i5-10310U CPU @ 1.70GHz
Memory: 15.3 Gio of RAM
Graphics Processor: Mesa Intel® UHD Graphics
Manufacturer: Dell Inc.
Product Name: Latitude 7410
Comment 7 Vlad Zahorodnii 2024-07-15 09:23:53 UTC
(In reply to Louis Moureaux from comment #6)
> Can reproduce 100% of the time when unplugging my USB-C monitor, with the
> same stack trace.

Is it reproducible when you have no apps open on desktop?
Comment 8 Louis Moureaux 2024-07-15 17:48:10 UTC
> Is it reproducible when you have no apps open on desktop?

Actually not. This is reliably reproducible with a Firefox window on the external screen, which I hadn't noticed because it's my standard setup.
Comment 9 Vlad Zahorodnii 2024-07-17 10:26:12 UTC
(In reply to Louis Moureaux from comment #8)
> > Is it reproducible when you have no apps open on desktop?
> 
> Actually not. This is reliably reproducible with a Firefox window on the
> external screen, which I hadn't noticed because it's my standard setup.

Hmm, it doesn't crash for me with firefox on an external screen. What's your output setup? does firefox create any new windows? can you please check what exactly in ff makes kwin crash?
Comment 10 Louis Moureaux 2024-07-19 03:23:30 UTC
Thank you for trying to reproduce!

The external monitor is a Samsung 1560x1440 panel connected over USB-C with attached mouse and keyboard. The laptop gets power from the external screen as well. The built-in screen has lower resolution, 1920x1280.

Unfortunately I am away from this specific setup for the coming weeks, but I'll try to recreate in another environment.
Comment 11 Bug Janitor Service 2024-07-22 12:16:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6152
Comment 12 Vlad Zahorodnii 2024-07-23 13:53:30 UTC
Git commit 02fbeeae78188c6e7aa4dd90c582faef1d678c01 by Vlad Zahorodnii.
Committed on 23/07/2024 at 13:46.
Pushed by vladz into branch 'master'.

Make Workspace::desktopResized() reassign outputs of uninitialized windows

If an output is deleted, the Workspace::desktopResized() is going to
re-assign windows to the new outputs. It is done so so the workspace
re-arrangement procedure is deterministic and has concrete order.

However, with the current Window lifecycle management, it's possible
to encounter the follwing case:

- xdg_toplevel gets created on output A
- xdg_toplevel initial state is committed
- output A is removed
- a wl_buffer is attached to the xdg_toplevel, which results in a
  geometry change and an output change
- Window::setMoveResizeOutput() is called, but the previous output
  is a dangling pointer

M  +2    -0    autotests/integration/CMakeLists.txt
A  +115  -0    autotests/integration/workspace_test.cpp     [License: GPL(v2.0+)]
M  +9    -0    src/workspace.cpp

https://invent.kde.org/plasma/kwin/-/commit/02fbeeae78188c6e7aa4dd90c582faef1d678c01
Comment 13 Bug Janitor Service 2024-07-23 13:55:42 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6162
Comment 14 Vlad Zahorodnii 2024-07-23 14:17:07 UTC
Git commit 65073ce6796fb6033929b5ce413612148eb7908e by Vlad Zahorodnii.
Committed on 23/07/2024 at 13:55.
Pushed by vladz into branch 'Plasma/6.1'.

Make Workspace::desktopResized() reassign outputs of uninitialized windows

If an output is deleted, the Workspace::desktopResized() is going to
re-assign windows to the new outputs. It is done so so the workspace
re-arrangement procedure is deterministic and has concrete order.

However, with the current Window lifecycle management, it's possible
to encounter the follwing case:

- xdg_toplevel gets created on output A
- xdg_toplevel initial state is committed
- output A is removed
- a wl_buffer is attached to the xdg_toplevel, which results in a
  geometry change and an output change
- Window::setMoveResizeOutput() is called, but the previous output
  is a dangling pointer


(cherry picked from commit 02fbeeae78188c6e7aa4dd90c582faef1d678c01)

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>

M  +2    -0    autotests/integration/CMakeLists.txt
A  +115  -0    autotests/integration/workspace_test.cpp     [License: GPL(v2.0+)]
M  +9    -0    src/workspace.cpp

https://invent.kde.org/plasma/kwin/-/commit/65073ce6796fb6033929b5ce413612148eb7908e
Comment 15 akhtaboot 2024-08-28 21:06:39 UTC
I'm on KDE Plasma Version 6.1.4 and it seems I'm not hitting this bug anymore, Thanks a lot for your work!


I still note some behavior that can be improved: when the external display is disconnected, the windows do not necessarily get moved to the now only screen.
Comment 16 Nate Graham 2024-08-28 21:22:40 UTC
Great!

That other issue is Bug 479694, which hopefully will be fully fixed in Plasma 6.1.5