dotnet / wpf

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

Random graphics corruption in a WPF app #3833

Closed jairbubbles closed 3 years ago

jairbubbles commented 3 years ago

Graphics randomly get corrupted in our application with no clue why. It takes different forms:

All those problems tend to happen at the same time.

When the corruption appears:

As the problem is quite tricky, I'm looking more for advice or debugging techniques I'm not aware of that could help me go deeper in the investigation.

Some additional info:

Thanks !

predavid commented 3 years ago

Thanks @jairbubbles for reporting the issue. Since this isn't a regression from .NET Framework 4.8, affects only a fraction of your users and dosen't have a consistent repro, we aren't able to investigate & rootcause the issue.

@ryalanms - are there additional debugging techniques you'd suggest for @jairbubbles to pursue?

jairbubbles commented 3 years ago

Thx @predavid that's exactly what I'm looking for: guidance 😁

For me the fact that we cannot Snoop the application is pretty peculiar and indicates that something really wrong is happening which I hoped could ring a bell to some WPF core engineers.

SamBent commented 3 years ago

Sorry, this doesn't ring any bells. I agree that it's peculiar, but I don't have any guesses as to what's happening. I assume you're looking for common factors among the repro cases: a particular activity in your app, something in the environment (OS, theme changes, screen DPI, per-monitor awareness, graphics HW/drivers, etc.). And that you've tried VS LiveVisualTree as well as Snoop.

The problems you illustrated are quite different - they don't point at any one suspect. Except that they all seem to be, broadly, "corruption in the visual tree". But corruption at that fundamental level tends to result in crashes or gross mis-display, not isolated glitches like a missing color here, missing text there, missing offset somewhere else.

As a last resort, I use WinDbgX to look at the raw data structures. But it's tedious, and you have to know what you're looking for. Open sources help, but obviously not a substitute for years of experience.

Any idea if this is happening to other apps? And whether the toolkit and/or Prism are implicated?

jpapp05 commented 3 years ago

Not sure if this helps, but I had a similar problem where the visual tree was empty and Snoop was unable to see anything. It took a while to find a fix, but in my case it had to do with with DPI settings and our use of custom themes. My theory was that our custom themes in some way, prevented needed initialize of WPFs high DPI support.

Some times by changing the DPI to different settings and dragging/resizing the app between monitors I was able to get the UI to suddenly snap back. It seemed to be caused by changes in .NET 4.8; the same code ran fine in .NET 4.7.2, even on high DPI systems. The only solution for us was to change how we enforced custom themes.

I never really figured what exactly was going on as it only effected a small subset of our users and only a subset of our products.

For more info: https://github.com/Microsoft/dotnet/issues/1026
Blank tool windows – ReSharper

ClosetBugSlayer commented 3 years ago

I see this corruption too, on .NET Core 3.1 and Windows 10 19041.610. It does not happen often and did not happen prior, but every now and then I'll see regions in my WPF window that didn't get repainted. I am running multiple UI threads (about 10) if that helps.

jairbubbles commented 3 years ago

Thx all for taking time to add all those info.

@jpapp05 @ClosetBugSlayer I'm not sure this is the same problem, in my case only some elements in the view have rendering issues.

@SamBent I couldn't find a common factor... and I don't reproduce it anymore on my computer so I can't really debug it more deeply. I realized that I changed my screen since then (125% DPI now) but it would make more sense that the problems appeared with the high DPI and not disappear.

Any idea if this is happening to other apps? And whether the toolkit and/or Prism are implicated?

We have one other application (but a lot simpler) which uses MaterialDesign but it doesn't have any problem, I checkedr the issues and nothing similar happened. As for Prism I doubt it can be a cause of the problem.

predavid commented 3 years ago

Hi @jairbubbles - I don't believe we have heard of other apps with the exact same issue. It's good to know that changing the screen to a higher DPI actually caused the issue to disappear instead of actually being amplified.

So, unless there are other repro steps or if you sight the problem again, can this Issue be closed ?

jairbubbles commented 3 years ago

This can be closed indeed.

Squall-Leonhart commented 3 years ago

This issue is antagonised by Windows updates, KB5004945 has introduced the same thing among a number of our users, but not others.

Matching those users resolution, depth, hdr and theme settings is not finding anything. users are running the same display driver as others that aren't affected.

GWawrzeniecki commented 3 years ago

This issue is antagonised by Windows updates, KB5004945 has introduced the same thing among a number of our users, but not others.

Matching those users resolution, depth, hdr and theme settings is not finding anything. users are running the same display driver as others that aren't affected.

How we can fix this? Did Microsoft release some Fix for that bug? I am developing a .NET WPF App and have the same problem also.

lindexi commented 3 years ago

@GWawrzeniecki

Did Microsoft release some Fix for that bug?

No.

Squall-Leonhart commented 3 years ago

The original issue in this thread may have actually been linked to another software on the issue creators system, refer to #707,

The regression that windows kb updates has introduced is specifically regarding that third party injection where a mechanism introduced in later versions of nahimic osd dll's is no longer working.

GWawrzeniecki commented 3 years ago

The original issue in this thread may have actually been linked to another software on the issue creators system, refer to #707,

The regression that windows kb updates has introduced is specifically regarding that third party injection where a mechanism introduced in later versions of nahimic osd dll's is no longer working.

Thank you for referring me that that issue! I was having the same issue but I didn't know how to name it. I have stopped the NahimicService and the bug is gone <3

HollowSun0 commented 2 years ago

The original issue in this thread may have actually been linked to another software on the issue creators system, refer to #707, The regression that windows kb updates has introduced is specifically regarding that third party injection where a mechanism introduced in later versions of nahimic osd dll's is no longer working.

Thank you for referring me that that issue! I was having the same issue but I didn't know how to name it. I have stopped the NahimicService and the bug is gone <3

wow thank you! This fixed my issue too.