maui icon indicating copy to clipboard operation
maui copied to clipboard

Window glitches when dragging app between monitors with different scaling

Open Felicity-R opened this issue 3 years ago • 4 comments

Description

Dragging a Maui app between different monitor causes visual glitches and eventually stops responding. See attached video to see what I mean: screen-capture.webm. In the video I'm just recording my 2nd monitor; the laptop screen is below it so that's where the app is when I drag it off screen below. In the end I need to ctrl+alt+delete to get to the task manager and force close it because everything stops responding.

Steps to Reproduce

  1. Have a dual-monitor setup
  2. Set custom scaling on monitor in the display settings. e.g. I have my laptop scaling set to 125% and a secondary monitor with scaling at 100%. (If I change the laptop to also be 100% scaling then the bug does not occur). image
  3. Create a new app from the .Net MAUI App template (using .Net7)
  4. Launch the app
  5. Drag the app from one monitor to the other. If it's still behaving normally, drag it back.

Expected results: You can freely move the app around and it will work fine.

Actual results: After moving from one monitor to the other a few times, it will break. Sometimes the app window flashes around wildly, sometimes just the edge of the window twitches - see video in description.

Link to public reproduction project repository

Can repro in the Maui template app

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10 19043.2251

Did you find any workaround?

Don't use different scaling

Relevant log output

No response

Felicity-R avatar Dec 01 '22 01:12 Felicity-R

If you try this in a WinUI application without MAUI, what happens?

drasticactions avatar Dec 01 '22 04:12 drasticactions

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Dec 01 '22 19:12 ghost

Good question. I tried with a new app from the "Blank App, Packaged (WinUI 3 in Desktop)" template, changed it to .net7 to match the Maui project and was not able to reproduce the issue there. I also tried adding a ScrollViewer and some TextBoxes there and still no repro. Then I pared down the Maui app, removing all the controls from the main page so it was just a blank page, and the Maui app still had the issue.

Felicity-R avatar Dec 01 '22 19:12 Felicity-R

I see the same behavior on my machine. One display is at 200% and a second one at 150%. I see different kinds of flickering effects and the content seems to toggle between both DPI settings (= sizes).

Based on the behavior my assumption is, that the MAUI window is doing some resizing strategy before the user releases the mouse cursor on the second screen

  1. It seems as if the window is being resized as a reaction to the message from Windows when moving to the second screen.
  2. As a result of the resizing the main part of the smaller window is now back on the first screen. =>
  3. Windows is sending a message to scale to this size.
  4. Maui rescales to the larger window and the main part of the window is on the second screen again =>
  5. goto 1

When I break the execution I always see stack trace like this:

image

DerPate2010 avatar Dec 07 '22 10:12 DerPate2010

I have the same issue with Maui Blazor App. One monitor is at 125% and the other is at 100%. When I drag the Maui app from the 125% monitor to the 100%, it gets stuck halfway, flickering as if re-rendering but the app itself is unresponsive and has to be killed off. On the other hand, if I drag from 100% to 125% the problem does not show up. As long as the app starts in a 100% scaling monitor it seems okay to be dragged afterward but not if it starts up in a 125% scaled monitor. You cannot drag back from 125% to 100%.

jerry-synap avatar Feb 17 '23 10:02 jerry-synap

I have the same issue with Maui Blazor App. any update?

LFXA avatar Apr 04 '23 10:04 LFXA

https://github.com/dotnet/maui/issues/14597#issuecomment-1509985432

This mentions the possible issue. Calculating the Width, Height, X, and Y could be causing it to redraw and freak out.

drasticactions avatar Apr 17 '23 06:04 drasticactions

Addition to my comment https://github.com/dotnet/maui/issues/14597#issuecomment-1509985432 If I add this line to the method, we can see that this FrameChanged method is in a hot path

if (_batchFrameUpdate > 0)
{
	Debug.WriteLine($"_batchFrameUpdate={_batchFrameUpdate}, frame={frame}");
}

Like this: image

I will get this when I move MAUI window from a monitor with 150% scaling to another one with 100% scaling:

_batchFrameUpdate=1, frame={X=-279 Y=160 Width=797 Height=1211}
_batchFrameUpdate=2, frame={X=-279 Y=160 Width=797 Height=807}
_batchFrameUpdate=2, frame={X=-186 Y=106.66666412353516 Width=797.3333129882812 Height=1210.6666259765625}
_batchFrameUpdate=3, frame={X=-186 Y=160 Width=797.3333129882812 Height=1210.6666259765625}
_batchFrameUpdate=1, frame={X=-519 Y=151 Width=797 Height=1211}
_batchFrameUpdate=2, frame={X=-519 Y=151 Width=797 Height=807}
_batchFrameUpdate=2, frame={X=-519 Y=151 Width=797 Height=1211}
_batchFrameUpdate=1, frame={X=-519 Y=151 Width=531 Height=1211}
_batchFrameUpdate=1, frame={X=-519 Y=151 Width=531 Height=807}

It seems to me that updating bindable properties in such hot path is not a good idea.

.

salarcode avatar Apr 17 '23 13:04 salarcode

https://github.com/dotnet/maui/blob/48d02949c511bd979f061343f90ea63cd227558e/src/Controls/src/Core/HandlerImpl/Window/Window.Impl.cs#L209-L212 These lines are causing performance regression imo

image

@jonathanpeppers pinging for help

salarcode avatar Apr 20 '23 20:04 salarcode

The picture of a stack trace above shows this is called:

https://github.com/dotnet/maui/blob/2b823f8503748f115028e671b4fff9048628c462/src/Core/src/Platform/Windows/WindowExtensions.cs#L26

Hoping this was profiled in Release mode, but can you share your profiler data here?

So, is this what is happening?

  1. User drags window
  2. Windows APIs -> tells MAUI the position changed
  3. MAUI OnPropertyChanged() -> calls Windows API to update position
  4. Repeat in a loop?

These lines are causing performance regression imo

Regression from what? .NET 6?

jonathanpeppers avatar Apr 20 '23 21:04 jonathanpeppers

Unfortunately i didn't save that file, wasn't expecting it be needed. And yes it was in Release mode.

Here is another run I did in Release mode. What I did is just run Maui.Controls.Sample and move the window between two monitors with different scaling as I've mentioned before. At the end I managed to glitch the app and it was stuck and unresponsive like this :

https://user-images.githubusercontent.com/1272095/233505719-065d6299-ccab-4c41-844a-5c8943d68260.mp4

Here is the profile session for above :

Report20230421-0905.zip

Regression from what? .NET 6?

I think based on #4942 yes.

salarcode avatar Apr 20 '23 23:04 salarcode

Sorry but we have to revert the PR that fixes this issue. We are working in improving the related fix to be merged on main. Thanks.

rmarinho avatar Aug 04 '23 15:08 rmarinho