dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.17k forks source link

Button renders wrong after mouse leave #707

Closed jorisvergeer closed 4 years ago

jorisvergeer commented 5 years ago
lindexi commented 5 years ago

I run your code but work fine in .NET Framework 4.8.

Minimum Repo:

https://github.com/lindexi/lindexi_gd/tree/7ec17c839ae8b07b3847245ced022a33e4d66f60/Nelirakuurkykeanrke

It run in .NET Framework 4.8.

https://github.com/lindexi/lindexi_gd/blob/7ec17c839ae8b07b3847245ced022a33e4d66f60/Nelirakuurkykeanrke/Nelirakuurkykeanrke/Nelirakuurkykeanrke.csproj#L11

Could you add some code in your AddNewConnectionWindow.xaml.cs ?

jorisvergeer commented 5 years ago

App.xaml.zip I have this issue with dotnet new wpf and just showing my window.

image

jorisvergeer commented 5 years ago

Let me add some information: My laptop had an Intel i7 with integrated graphics and a Nvidia 1050 GPU.

To me it looks like that during drawing some framebuffers or textures are messed up, or wrong ones are used.

jorisvergeer commented 5 years ago

I tried this on another PC at work. There it shows the correct behavior.

Throwing this bug in the category that depends on the environment it runs on.

lindexi commented 5 years ago

@jorisvergeer Could you find if some drivers are not installed on your device?

jorisvergeer commented 5 years ago

As far as I am aware, I have all drivers installed. I was able to play some games last night.

jorisvergeer commented 5 years ago

Are there any commands or tools I can run on my PC to diagnose the drawing? Or to debug the whole .net wpf drawing code.

jorisvergeer commented 5 years ago

Anyway, What I guess that happend om my machine it this:

(Approximation with Paint)

It wants to draw this: image Accidently draws a button on with its parents (or window, they are the same) size (I saw something like this on one occasion when switching windows): image Then only draws the portion in the buttons region: image

lindexi commented 5 years ago

Are there any commands or tools I can run on my PC to diagnose the drawing? Or to debug the whole .net wpf drawing code.

Yes, the Performance Profiling Tools for Windows Presentation Foundation may help you to find the dirty region.

jorisvergeer commented 5 years ago

@lindexi That tool does not seem to work with dotnet core 3.0 WPF

walterlv commented 5 years ago

@jorisvergeer The tool works fine with .NET Core 3.0 WPF application. I've tested it a few weeks ago.

I wrote a post for my demo and you may read the English translated version:

jorisvergeer commented 5 years ago

@walterlv @lindexi You are right. But you have to have the "Perforator" tab open. Otherwise it doesn't work.

I'll try it when I get home.

0xd4d commented 5 years ago

Possibly related to https://github.com/dotnet/wpf/issues/319

jorisvergeer commented 5 years ago

@0xd4d Its probably related.

jorisvergeer commented 5 years ago

I don't know if it is worth anything:

jorisvergeer commented 5 years ago

Just captured another fun example: image

jorisvergeer commented 5 years ago

I guess that somewhere, somehow, some active framebuffery-kind objects are being reused, leaked or mixed up.

stevenbrix commented 5 years ago

@jorisvergeer what's your screen resolution and scale factor? Are you using multiple monitors?

jorisvergeer commented 5 years ago

@stevenbrix My laptop has 1920x1080 as resulution is uses the default scale factor. My laptop is of type MSI GF63 8RD

A maybe interesting detail is that is one of those laptops which has dual graphics card. intel and nvidia

weltkante commented 5 years ago

I doubt that its got anything to do with DPI/resolution, that would probably keep aspect ratio and not just stretch the image to the window size. Probably more likely something to do with drivers/hardware. The other issue linked above #319 (closed as duplicate) was also reproduced on an integrated intel chipset.

Doesn't WPF have a way to force software rendering? Google finds things like this, if these work in .NET Core maybe someone who can reproduce the problem can check if it goes away when forcing WPF to render in software.

MrPurple6411 commented 5 years ago

Just as a bit of extra info... I am running a MSI GL73 8RC laptop so pretty close to OP's computer and I am having this same issue using version 2.2.401 skd and 2.2.6 runtime. I think it might be a graphics driver issue but at the same time it happens when I force it to run on the gtx 1050 as well as the intel integrated chip. All drivers are current and up to date. happens on both x86 and x64 versions of dnspy and WPF

tried with same install on my desktop with only gtx 1050 and there was no issue.

stevenbrix commented 5 years ago

I am having this same issue using version 2.2.401 skd and 2.2.6 runtime

@MrPurple6411 WPF has only been ported to .NET Core beginning with 3.0, so I'm curious how you are using 2.x sdk and runtime?

My Surface Book 2 has the gtx 1060 and integrated intel graphics card and i'm not seeing this, so I wonder if it has something to do with the 1050. I'll be working on getting a device to see if i can repro this. Thanks everyone for the info so far!

stevenbrix commented 5 years ago

@PascalKoe (who opened #319) mentioned that he was just using the integrated Intel graphics. I'd be curious to know more about your hardware.

I tried this on a Lenova Yoga with the same Intel integrated graphics and Nvidia GTX1050 configuration and didn't reproduce this. I'm beginning to think it might not have as much to do with the GTX1050 as it does with the intel integrated graphics (or possibly something else on the board). I'm hoping I can get my hands on one of these MSI laptops to reproduce this issue.

For those that can reproduce this, are there any other scenarios or times where you see this behavior? Does this always happen with the sample app and DnSpy, or is there a time when it renders as expected?

If you could try and build the D3D9 sample here and see if there are any issues with it. You'll probably also need to install the DirectX SDK here. This will help us understand if it's an issue with WPF or the graphics stack.

stevenbrix commented 5 years ago

@jorisvergeer would you be able to share a VS Live Share session with me sometime so I can take a look under a debugger?

jorisvergeer commented 5 years ago

@stevenbrix That would be possible

stevenbrix commented 5 years ago

@jorisvergeer actually even better would be to collect a Time Travel trace using WinDbg Preview and share that with us. One for both framework and core would be really helpful!

Steps for collecting a Time Travel trace

  1. If you don't already have WinDbg Preview, you can install it from here: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/windbg-install-preview
  2. Launch WinDbg Preview as Admin
  3. Go to File ->Start debugging -> Launch executable (advanced)
  4. Give path to executable and check "Record process with Time Travel Debugging"

I've included a picture below of what your window should look like:

image

jorisvergeer commented 5 years ago

@stevenbrix I've done that, I have 3 files totalling about 2.5GiB of data. How do you want to receive it?

stevenbrix commented 5 years ago

@jorisvergeer If you can upload it to some cloud storage provider like OneDrive or DropBox and provide me a link so I can download them that would be great! Or if you'd prefer, I could provide a link to my OneDrive for you to upload them to.

jorisvergeer commented 5 years ago

@stevenbrix Here you go, I've uploaded it temporary to my own VPS, tell me when you are done.

https://vpn01.jorisvergeer.nl/wpftest/

stevenbrix commented 5 years ago

@jorisvergeer got it, thank you!!

jorisvergeer commented 5 years ago

@stevenbrix I see that you requested both core and framework. I only did a run with core. Let me know if you want data for framework also still.

stevenbrix commented 5 years ago

@jorisvergeer that would be super helpful! It'll be helpful to compare the framework and core traces from the same machine.

jorisvergeer commented 5 years ago

Just a sec.

Meanwhile: Behaviour also appears in the visual studio editor:

image

jorisvergeer commented 5 years ago

@stevenbrix I did a run win .net 4.7.2, no weird behaviour as expected.

There is a file WpfTest01_net472.zip in the same location.

vatsan-madhavan commented 5 years ago

If you could try and build the D3D9 sample here and see if there are any issues with it.

Did this run without problems ?

PascalKoe commented 5 years ago

I don't know why, but I can't reproduce the bug anymore... The only thing I can remeber I changed are my two displays (Dell U2412M 16:10 1920x120 and an old Samsung 1280x1024) to one 32:10 Samsung display. Just tried with the old monitors but no luck so far. Going to take a spare drive and do a fresh install of Windows to see if it then reproduces again...

@stevenbrix You asked for the specs of the custom build computer: CPU: Intel Core i9-9900k Graphics: Intel(R) UHD Graphics 630 Motherboard: Asus ROG STRIX Z390-F GAMING RAM: HyperX Predator DDR4-3200 32GB Kit SSD: Samsung 970 Evo M.2 1000GB

jorisvergeer commented 5 years ago

If you could try and build the D3D9 sample here and see if there are any issues with it.

Did this run without problems ?

I am trying now

jorisvergeer commented 5 years ago

@stevenbrix @vatsan-madhavan I do run into issues.

When started with "Intel integrated graphics": I could increase complexity until i became bored image

When started with "High Performance NVIDIA processor": Initially a lot of black. image

When playing with increase and decrease complexity, from time to time the background comes back to live, only to show just a couple of frames, or be stuck when changing complexity.

image

jorisvergeer commented 5 years ago

Note that with WPF it does not matter if I start my example app with one or the other graphics processor. Both show the same glitches.

stevenbrix commented 5 years ago

@jorisvergeer can you try disabling NahimicOSD and see if that fixes the issue? It looks like that is hooking into the Present calls on one of traces and not the other.

jorisvergeer commented 5 years ago

@stevenbrix didn't even know i had NahimicOSD

jorisvergeer commented 5 years ago

@stevenbrix I think you are on to something

I stopped the Nahimic Service, and suddenly WPF acted just fine.

jorisvergeer commented 5 years ago

@stevenbrix I started the service again, and the glitches were back

stevenbrix commented 5 years ago

@jorisvergeer sounds like we've definitely found our culprit then! I have no idea why that audio service would be causing this. I've sent them a support request, hopefully they are responsive 🤞

jenatali commented 5 years ago

@jorisvergeer @stevenbrix my best guess here is that Nahimic has an overlay that they can render. When they do their overlay rendering, they probably change the viewport to cover the entire swapchain, and don't change it back to what the application had set. Then when WPF goes to render, it assumes that the viewport is still what it was last time, and if the only thing that changed was the same thing that changed last time, then it doesn't try to update the viewport. If Nahimic was involved, then it ends up rendering something that was supposed to be a sub-rect into the entire swapchain.

In this case, they're not drawing their overlay... but they're still changing the viewport it seems. This is more or less a guess, but it fits the symptoms and wouldn't surprise me.

jorisvergeer commented 5 years ago

@stevenbrix @jenatali @vatsan-madhavan If @jenatali his hypothesis is true, is it then not a bug in WPF that it assumes that the viewport was not changed. Can we not just always set the correct viewport?

weltkante commented 5 years ago

@jorisvergeer no its not a bug in WPF if some 3rd party application hijacks Windows APIs and changes their semantics. The viewport is a variable of the DirectX session and as such under the control of WPF. If this were C# this would be the equivalent of someone else going around changing random private variables via reflection. It is not reasonable to write defensive code against that, anything you add will be subject to the next generation of 3rd party "improvement" hacks. How many backup copies of the viewport settings would you want to keep around to make sure nobody tampered with them?

jorisvergeer commented 5 years ago

@weltkante That could be, but somehow from all applications I am running, only WPF has this issue.

And also, I just won't use WPF in my applications if I know that it WILL glitch on fresh out of the box computers from some brands.

weltkante commented 5 years ago

Adding workarounds in WPF will just make the 3rd party product staying broken and failing for any number of other applications. You are fixing your immediate problem by making it worse for everyone else in the long term. There needs to be back pressure to vendors and distributors of broken "improvement" hacks to actually fix or remove them. This can only happen by taking the time to identify them as broken. Since the symptoms have been root caused once now, future identification will probably be a lot easier.

I vote for not adding workarounds to correct code. If this is so bad to warrant logic in WPF it should be checking the modules list and blacklisting known bad modules, like it has been practice with video drivers containing known bugs for a long time.

The decision is on Microsoft of course.

PudottaPommin commented 4 years ago

Just to add one of the possible culprits, I did not have Nahimic, but Realtek Sonic Studio, which caused this buggy behaviour :)