Bug 440751 - Opened windows are not getting drawn when 'Show Desktop' is abused in a loop
Summary: Opened windows are not getting drawn when 'Show Desktop' is abused in a loop
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: effects-window-management (show other bugs)
Version: 5.22.90
Platform: Arch Linux Linux
: VHI grave
Target Milestone: ---
Assignee: KWin default assignee
URL: https://codereview.qt-project.org/c/q...
Keywords: regression
: 442411 442649 443633 444610 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-08-08 18:36 UTC by valdikss
Modified: 2021-10-29 17:56 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Kde show desktop bug video demo (1.22 MB, video/mp4)
2021-08-08 18:36 UTC, valdikss
Details
qjsengine bug reproducer (4.20 KB, application/zip)
2021-10-05 14:09 UTC, Vlad Zahorodnii
Details

Note You need to log in before you can comment on or make changes to this bug.
Description valdikss 2021-08-08 18:36:44 UTC
Created attachment 140589 [details]
Kde show desktop bug video demo

SUMMARY

Using 'Show Desktop' function multiple (tens) times result in all opened windows on current desktop to not render at all. They act as they are shown on desktop, but no elements are drawn, not even window header.


STEPS TO REPRODUCE

1. Open any graphical application, say Kate.
2. Press and hold CTRL+F12 (default 'show desktop' combination) for 10-30 seconds.


OBSERVED RESULT

Kate window is not displayed on screen while still present in task manager. You can 'minimize' and 'restore' the window, the cursor changes its shape where Kate text field should be shown, but the window is just not rendered: not the content, not the WM header with title and buttons.


EXPECTED RESULT

Window is rendered as usual.


SOFTWARE/OS VERSIONS

Operating System: Fedora 34
KDE Plasma Version: 5.22.4
KDE Frameworks Version: 5.83.0
Qt Version: 5.15.2
Kernel Version: 5.13.6-200.fc34.x86_64 (64-bit)
Graphics Platform: X11
Graphics Processor: Mesa DRI Intel® HD Graphics 3000


ADDITIONAL INFORMATION

Please watch the video if the text description is confusing.
I'm not sure whether this is a kwin or plasma bug. Filing it as kwin bug (as even window decorations are not shown), please reassign if necessary.
Comment 1 valdikss 2021-08-08 18:42:19 UTC
Note that keyboard repeat rate could be very low to trigger this bug, so it doesn't seem like race condition. The video has repeat rate of 3 per second.
Comment 2 Nate Graham 2021-08-09 16:35:04 UTC
I can confirm this. I just started seeing it yesterday on Wayland and found that I could reproduce it pretty reliably by showing the Widget Explorer (which automatically invokes Present Windows), dragging a widget to the desktop, and interacting with the desktop at all. Thereafter, the Present Windows effect has restored all the windows, but they are invisible.

If I quit an affected app and re-launch it, its window is rendered properly.
Comment 3 Nate Graham 2021-09-16 17:34:32 UTC
*** Bug 442411 has been marked as a duplicate of this bug. ***
Comment 4 Mithrannussen 2021-09-17 15:59:16 UTC
I apologize for previously creating a duplicate report of this one. I said that I had issues when running under xrender also, however it was a mistake I no longer have such issues in kwin, expect when utilizing any opengl compositor. Thanks for the attention.
Comment 5 Nate Graham 2021-09-17 17:47:57 UTC
I just hit this effect when using the Eye On Screen effect instead of Window Aperture, so it doesn't seem specific to that effect.

Notably, I also just discovered opening System Settings and switching from one effect to the other makes all the missing windows re-appear.
Comment 6 Szymon 2021-09-18 11:43:20 UTC
When we change the options "Show Desktop" to "Minimize all Windows" another problem occurs ( Wayland only ) . Depending on what application is active ( window ) this function works as expected. But when we reshuffle the windows activity , there is a problem.

Description of the Problem : The windows hide, but after clicking again they do not show up. They are still hidden and this function does not work until we manually restore the windows one by one.

Opening the Problem : Launch the Dolphin and Kate applications. Make sure that the windows are visible on your screen. And then remember which window was active. Use the Minimize all Windows function twice via shortcut or applet. If the windows are still active the second time, change the windows activity to the other application and use the function twice again.

PS. I am not quite sure if the function error itself occurs only when using it , or for other reasons. However, if the problem does not appear, please use more applications, and change their activity, surely it will appear.
Comment 7 Nate Graham 2021-09-21 21:58:33 UTC
*** Bug 442649 has been marked as a duplicate of this bug. ***
Comment 8 Nate Graham 2021-10-02 03:38:01 UTC
I don't know if something recent fixed this, but I'm no longer able to reproduce the issue with today's git master. I realize it's been a few days since it happened to me, whereas before I was hitting it at least once a day, sometimes more often.
Comment 9 valdikss 2021-10-02 13:00:31 UTC
The bug still exists in 
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.85.0
Comment 10 Vlad Zahorodnii 2021-10-05 14:09:53 UTC
Created attachment 142167 [details]
qjsengine bug reproducer

I found a reliable way to reproduce the issue in QJSEngine. Key points:

* several engines need to work with the same qobject
* if garbage collector runs at some specific point, it seems like qobject wrappers will be destroyed

if you run the demo, you're going to see

js: customProp2 was stripped away for EffectWindow(0x55d553dc1d50)
js: customProp2 was stripped away for EffectWindow(0x55d553dc1b30)
js: customProp2 was stripped away for EffectWindow(0x55d553dc1f70)

ideally, the demo should not print anything.
Comment 11 Vlad Zahorodnii 2021-10-10 17:26:51 UTC
I think I found the culprit of this bug. The garbage collector seems to prefer to keep "null or undefined" qobject wrappers in MemoryManager::sweep() https://code.woboq.org/qt5/qtdeclarative/src/qml/memory/qv4mm.cpp.html#983

    if (MultiplyWrappedQObjectMap *multiplyWrappedQObjects = engine->m_multiplyWrappedQObjects) {
        for (MultiplyWrappedQObjectMap::Iterator it = multiplyWrappedQObjects->begin(); it != multiplyWrappedQObjects->end();) {
            if (!it.value().isNullOrUndefined())
                it = multiplyWrappedQObjects->erase(it);
            else
                ++it;
        }
    }

That looks very sketchy. If `!it.value().isNullOrUndefined()` is changed to `it.value().isNullOrUndefined()`, tainted qobject wrappers don't get destroyed.
Comment 12 Nate Graham 2021-10-12 21:32:56 UTC
Vlad's patch (https://codereview.qt-project.org/c/qt/qtdeclarative/+/376014) has been merged, so this is officially fixed in Qt. We'll see about backporting the fix to the KDE patch collection for Qt 5.15.
Comment 13 Nate Graham 2021-10-13 03:58:28 UTC
Qt backport request: https://invent.kde.org/qt/qt/qtdeclarative/-/merge_requests/8
Comment 14 Nate Graham 2021-10-18 03:19:19 UTC
*** Bug 443633 has been marked as a duplicate of this bug. ***
Comment 15 Nate Graham 2021-10-29 17:56:57 UTC
*** Bug 444610 has been marked as a duplicate of this bug. ***