Bug 442990 - Crash in KWin::Toplevel::setOutput()
Summary: Crash in KWin::Toplevel::setOutput()
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: wayland-generic (show other bugs)
Version: 5.22.90
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-26 17:32 UTC by Matej Mrenica
Modified: 2021-10-04 18:38 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matej Mrenica 2021-09-26 17:32:48 UTC
SUMMARY
Kwin and the entire session crashed after laptop woke up from sleep. During logging in, the lock screen was flashing.

SOFTWARE/OS VERSIONS
KDE Frameworks Version: 5.86
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Log: https://pastebin.com/csCqAgs0
Comment 1 Matej Mrenica 2021-09-26 17:35:11 UTC
To add more info, laptop was waking up with its lid closed, monitor connected but not turned on (yet).
Comment 2 David Edmundson 2021-09-26 19:54:27 UTC
Pasting inline

>                Stack trace of thread 951:
                #0  0x00007f25626c4407 _ZN4KWin8Toplevel9setOutputEPNS_14AbstractOutputE (libkwin.so.5 + 0x236407)
                #1  0x00007f2562700c39 _ZN4KWin9Workspace18slotOutputDisabledEPNS_14AbstractOutputE (libkwin.so.5 + 0x272c39)
                #2  0x00007f2560cef39b n/a (libQt5Core.so.5 + 0x2fc39b)
                #3  0x00007f2562568e93 _ZN4KWin8Platform14outputDisabledEPNS_14AbstractOutputE (libkwin.so.5 + 0xdae93)
                #4  0x00007f255980d4be _ZN4KWin10DrmBackend12removeOutputEPNS_17DrmAbstractOutputE (KWinWaylandDrmBackend.so + 0x1c4be)


The number of threads is very surprising. I don't know if that's real or coredumpctl getting confused.
Comment 3 Vlad Zahorodnii 2021-09-27 06:57:19 UTC
Not sure how kwin can crash in Toplevel::setOutput(). Either the window is deleted, which is strange as the stacking order should not contain dangling pointers, or the output is destroyed, which is also weird because it gets destroyed after emitting outputDisabled() and outputRemoved() signals.
Comment 4 Zamundaaa 2021-10-02 13:16:47 UTC
The same crash happened to me now as well on git master when changing Picture by Picture mode on my monitor (which . It crashes on
qreal newScale = m_output->scale();
because the output found in Workspace::slotOutputDisabled is nullptr.

At least in my case it seems like one output isn't enabled and the other is getting removed, so the placeholder output isn't created.
Comment 5 Bug Janitor Service 2021-10-02 13:24:17 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/1486
Comment 6 Matej Mrenica 2021-10-02 14:51:13 UTC
Looking at the proposed changes, it looks like it would fix the issue of laptop screen not being turned on if an external monitor is unplugged? Because that's something I was considering reporting.
Comment 7 Zamundaaa 2021-10-02 14:57:02 UTC
Yes it should, although KScreen should also already be turning the output on.

If I interpret this correctly your setup is having the internal display disabled, with the external one used? Is that also the situation where this crash happens?
Comment 8 Matej Mrenica 2021-10-02 15:38:13 UTC
(In reply to Zamundaaa from comment #7)
> Yes it should, although KScreen should also already be turning the output on.
> 
> If I interpret this correctly your setup is having the internal display
> disabled, with the external one used? Is that also the situation where this
> crash happens?

Yes, that's correct, the crash happens when I disconnect an external monitor (Or when I reconnect it) if it's the only enabled screen. I did that just now and got the exact same output.
Comment 9 Matej Mrenica 2021-10-02 16:34:06 UTC
Your proposed change fixes this issue mostly.
Session/kwin doesn't crash anymore and the internal screen is activated.
But, plasmashell still crashes and there isn't a coredump generated.
Comment 10 Nate Graham 2021-10-02 16:45:26 UTC
Since this bug report is about KWin crashing, let's get a new one for plasmashell once this is fixed. It might also just be Bug 420160?
Comment 11 Matej Mrenica 2021-10-02 16:52:05 UTC
(In reply to Nate Graham from comment #10)
> Since this bug report is about KWin crashing, let's get a new one for
> plasmashell once this is fixed. It might also just be Bug 420160?

Yes, it seems to be the same issue:

...
Old primary output: QScreen(0x5646dd677450, name="HDMI-A-1") New primary output: QScreen(0x5646e12d8b70, name="")
...
xdg_surface@44: error -1: invalid window geometry size (0x0)
...
The Wayland connection experienced a fatal error: Protocol error
Comment 12 Zamundaaa 2021-10-04 09:38:09 UTC
Git commit 178e69b39b7c7ccc4e3d9f4ea85b2fde15eeac2a by Xaver Hugl.
Committed on 04/10/2021 at 09:37.
Pushed by zamundaaa into branch 'master'.

platforms/drm: handle hotplugs with disabled outputs better

If the last enabled output gets removed but we have disabled outputs
still connected, enable the first disabled output to prevent a crash.

M  +8    -0    src/plugins/platforms/drm/drm_backend.cpp

https://invent.kde.org/plasma/kwin/commit/178e69b39b7c7ccc4e3d9f4ea85b2fde15eeac2a
Comment 13 Zamundaaa 2021-10-04 09:38:31 UTC
Git commit 60bcccd0cfe7c8d9889f49aaee5dad9af3245d30 by Xaver Hugl.
Committed on 04/10/2021 at 09:38.
Pushed by zamundaaa into branch 'Plasma/5.23'.

platforms/drm: handle hotplugs with disabled outputs better

If the last enabled output gets removed but we have disabled outputs
still connected, enable the first disabled output to prevent a crash.


(cherry picked from commit 178e69b39b7c7ccc4e3d9f4ea85b2fde15eeac2a)

M  +8    -0    src/plugins/platforms/drm/drm_backend.cpp

https://invent.kde.org/plasma/kwin/commit/60bcccd0cfe7c8d9889f49aaee5dad9af3245d30