Bug 473807 - Games freeze when restarting the monitor they're being displayed on
Summary: Games freeze when restarting the monitor they're being displayed on
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: wayland-generic (show other bugs)
Version: 5.27.7
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: multiscreen, wayland
Depends on:
Blocks:
 
Reported: 2023-08-27 13:50 UTC by Fahim Shahriar
Modified: 2023-09-19 16:03 UTC (History)
4 users (show)

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


Attachments
Screenshot of Display and Monitor settings after turning on the monitor. (79.03 KB, image/png)
2023-08-27 13:50 UTC, Fahim Shahriar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fahim Shahriar 2023-08-27 13:50:11 UTC
Created attachment 161222 [details]
Screenshot of Display and Monitor settings after turning on the monitor.

SUMMARY
When I turn off my monitor by pressing the physical button on it, then turn it back on, Plasma detects a new display output and reloads the display settings. I know this by checking "Display and Monitor settings", where I see a new popup saying "A new output has been added. Settings has been reloaded".

STEPS TO REPRODUCE
- From a running system, turn off the monitor and turn it back on.

OBSERVED RESULT
Plasma is initializing a new display output and reloading all of the settings. The problem with it is that if some heavy task is running, like a game, restarting the monitor results in freezing or sometimes even crashing the task. Sometimes the whole desktop crashes and restarts itself. And sometimes (rarely) the whole system freezes and becomes unusable. Need to reboot in order to make it usable again.

EXPECTED RESULT
It should resume the display from where it has been left off. Shouldn't reload the settings.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20230823
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
Kernel Version: 6.4.11-1-default (64-bit)
Graphics Platform: Wayland
Processors: 4 × AMD Ryzen 3 3200G with Radeon Vega Graphics
Memory: 13.5 GiB of RAM
Graphics Processor: AMD Radeon Vega 8 Graphics
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7C52
System Version: 1.0

ADDITIONAL INFORMATION
- Unplugging the monitor should result in a same behavior, but I haven't tested it. 
- I haven't tested it on multi-monitor. 
- The issue is present on both Wayland and X11 session. 
- I'm using HDMI for display output.
- Have tested on Fedora and openSUSE. Problem persists.
Comment 1 Nate Graham 2023-08-28 21:39:50 UTC
When this happens, are your display settings also reset? e.g. display resolution, scale, refresh rate, position, etc?

Or are all of those settings remembered, and the problem is that there's a spike in system load that causes other issues?
Comment 2 Fahim Shahriar 2023-08-29 05:29:20 UTC
(In reply to Nate Graham from comment #1)
> When this happens, are your display settings also reset? e.g. display
> resolution, scale, refresh rate, position, etc?
> 
> Or are all of those settings remembered, and the problem is that there's a
> spike in system load that causes other issues?

I've tried applying different resolution and refresh rate and seems like all of the settings are remembered, they aren't resetting. And no, I don't see any spike in system load.
Comment 3 Nate Graham 2023-08-29 15:52:26 UTC
Okay, so the problem isn't a settings reset and it isn't a load spike. 

So is the problem a crash, or a system hang, or something else?
Comment 4 Fahim Shahriar 2023-08-29 18:17:39 UTC
(In reply to Nate Graham from comment #3)
> Okay, so the problem isn't a settings reset and it isn't a load spike. 
> 
> So is the problem a crash, or a system hang, or something else?

As I've described the issue in the report. It only effects the system when it's under heavy load. The task freezes or crashes. Let me elaborate my thinking.

N.B: THE FOLLOWING IS TOTALLY MY UNDERSTANDING.
I think when I turn on the monitor, as it initializes a new output, it tries to move everything from the previous display to the new one that it just initialized. It can do it. But when it finds some heavy task like games or something, it can't do it properly. And then the task freezes.

Here's a video of the issue if you find it helpful: https://youtu.be/iInDMAs63Kw
Comment 5 Nate Graham 2023-08-30 16:12:13 UTC
Thanks for the video, it helps.

To make sure I'm understanding it properly: when you are playing a full-screen game and you turn off your screen and then turn it on again, the game has stopped responding to input, and the Plasma Panel has inappropriately appeared on top of it, at the bottom of the screen.

Is that correct?
Comment 6 Fahim Shahriar 2023-08-31 05:47:42 UTC
(In reply to Nate Graham from comment #5)
> Thanks for the video, it helps.
> 
> To make sure I'm understanding it properly: when you are playing a
> full-screen game and you turn off your screen and then turn it on again, the
> game has stopped responding to input, and the Plasma Panel has
> inappropriately appeared on top of it, at the bottom of the screen.
> 
> Is that correct?
For the specific game in the video, yes.
For other games or tasks, the behavior can be different. But in all cases, the game or task freezes.

> game has stopped responding to input
And a small correction, just "game has stopped responding to input" - it's not like that. The game is completely frozen. The visuals as well.
Comment 7 Fahim Shahriar 2023-08-31 05:50:47 UTC
(In reply to Nate Graham from comment #5)
> full-screen game and you turn off your screen and then turn it on again
And it doesn't matter if the game is full-screen or not. It happens even if the game is windowed.
Comment 8 Oded Arbel 2023-08-31 08:00:29 UTC
(In reply to Fahim Shahriar from comment #7)
> And it doesn't matter if the game is full-screen or not. It happens even if
> the game is windowed.

When the game is not full-screen, and you encounter this behavior - is the plasma panel frozen or maybe it disappears and reappears?
Comment 9 Fahim Shahriar 2023-08-31 11:59:21 UTC
(In reply to Oded Arbel from comment #8)
> (In reply to Fahim Shahriar from comment #7)
> > And it doesn't matter if the game is full-screen or not. It happens even if
> > the game is windowed.
> 
> When the game is not full-screen, and you encounter this behavior - is the
> plasma panel frozen or maybe it disappears and reappears?

No. Panel is working fine when I do it.
Comment 10 Nate Graham 2023-08-31 18:52:04 UTC
Ok, so the issue happens with that game, whether fullscreen or windowed.

Does it happen with any other games, either fullscreen or windowed? Or just that one? Or just a few select games?

Does it happen with any fullscreen windows that are not games, such as Firefox?
Comment 11 Fahim Shahriar 2023-09-01 05:38:21 UTC
(In reply to Nate Graham from comment #10)
> Ok, so the issue happens with that game, whether fullscreen or windowed.
Yes.
> Does it happen with any other games, either fullscreen or windowed? Or just
> that one? Or just a few select games?
I've tested it with several games. It happens with every game.
> Does it happen with any fullscreen windows that are not games, such as
> Firefox?
No. But the focus of any fullscreen window is lost when I do it. Here's a video which explains the situation: https://youtu.be/wQJ_GW4Eg6U
Comment 12 Nate Graham 2023-09-01 16:04:13 UTC
Ok, thanks. Moving to KWin for further investigation.
Comment 13 Zamundaaa 2023-09-19 16:03:28 UTC
Windows losing focus is caused by plasmashell creating a new desktop window, which steals focus away (https://invent.kde.org/plasma/kwin/-/merge_requests/4349).

> EXPECTED RESULT
> It should resume the display from where it has been left off. Shouldn't reload the settings

Your monitor is getting disconnected and reconnected. The system can't not react to that. Let's focus on the actual problem at hand: the game freezes.

I tested this situation with a few games myself and I can somewhat confirm this:
- The Entropy Center becomes completely black and doesn't react to inputs / has to be killed
- CS:GO continues to work just fine
- Red Dead Redemption becomes black and doesn't react to inputs
- Horizon Zero Dawn freezes with part of the window becoming black, after minimize+maximize also completely black, and also doesn't react to inputs
- Xonotic continues to work just fine

The pattern I see here is that all affected games are using Proton, and it looks like there's already a bug report about this sort of thing for it: https://github.com/ValveSoftware/Proton/issues/7021