dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.87k stars 4.88k forks source link

WPF crash with UCEERR_RENDERTHREADFAILURE #1995

Closed rido-min closed 5 years ago

rido-min commented 5 years ago

WPF crash with UCEERR_RENDERTHREADFAILURE

General

I found this issue when trying to port MahApps to .NET Core 3.0. They have a dependency on ControlzEx to customize Windows.

I've been able to repro the issue on my CotrolzEx fork

System.Runtime.InteropServices.COMException
  HResult=0x88980406
  Message=UCEERR_RENDERTHREADFAILURE (Exception from HRESULT: 0x88980406)
  Source=PresentationCore
  StackTrace:
   at MS.Internal.HRESULT.Check(Int32 hr)
   at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
   at System.Windows.Media.MediaContext.CompleteRender()
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

and the full call stack from VS:

    PresentationCore.dll!MS.Internal.HRESULT.Check(int hr)  Unknown
    PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush()  Unknown
    PresentationCore.dll!System.Windows.Media.MediaContext.CompleteRender() Unknown
    PresentationCore.dll!System.Windows.Interop.HwndTarget.OnResize()   Unknown
    PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
    PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)   Unknown
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)   Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg)    Unknown
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)   Unknown
    PresentationFramework.dll!System.Windows.Window.Show()  Unknown
>   ControlzEx.dll!ControlzEx.Behaviors.GlowWindowBehavior.Show() Line 359  C#
    ControlzEx.dll!ControlzEx.Behaviors.GlowWindowBehavior.AssociatedObjectOnLoaded(object sender, System.Windows.RoutedEventArgs routedEventArgs) Line 211 C#
    ControlzEx.dll!ControlzEx.Behaviors.GlowWindowBehavior.OnAttached() Line 92 C#
    System.Windows.Interactivity.dll!System.Windows.Interactivity.Behavior.Attach(System.Windows.DependencyObject dependencyObject) Unknown
    System.Windows.Interactivity.dll!System.Windows.Interactivity.BehaviorCollection.ItemAdded(System.Windows.Interactivity.Behavior item)  Unknown
    System.Windows.Interactivity.dll!System.Windows.Interactivity.AttachableCollection<System.Windows.Interactivity.Behavior>.OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown
    PresentationCore.dll!System.Windows.FreezableCollection<System.__Canon>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)  Unknown
    PresentationCore.dll!System.Windows.FreezableCollection<System.__Canon>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, int oldIndex, System.__Canon oldValue, int newIndex, System.__Canon newValue)  Unknown
    PresentationCore.dll!System.Windows.FreezableCollection<System.__Canon>.AddHelper(System.__Canon value) Unknown
    PresentationCore.dll!System.Windows.FreezableCollection<System.__Canon>.Add(System.__Canon value)   Unknown
    ControlzEx.CoreDemo.dll!ControlzEx.Showcase.WindowChromeWindow.InitializeGlowWindowBehavior() Line 81   C#
    ControlzEx.CoreDemo.dll!ControlzEx.Showcase.WindowChromeWindow.WindowChromeWindow_ContentRendered(object sender, System.EventArgs e) Line 37    C#
    PresentationFramework.dll!System.Windows.Window.OnContentRendered(System.EventArgs e)   Unknown
    PresentationFramework.dll!System.Windows.Window.PostContentRendered.AnonymousMethod__202_0(object unused)   Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()   Unknown
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)  Unknown
    WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)   Unknown
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)   Unknown
    WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)  Unknown
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()   Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()  Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)  Unknown
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)   Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg)    Unknown
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    WindowsBase.dll!System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(ref System.Windows.Interop.MSG msg) Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)   Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)   Unknown
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()   Unknown
    PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)   Unknown
    PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)  Unknown
    PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)  Unknown
    PresentationFramework.dll!System.Windows.Application.Run()  Unknown
    ControlzEx.CoreDemo.dll!ControlzEx.Showcase.App.Main()  Unknown

Runtime environment

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-alpha1-009642
 Commit:    8cd38e2a49

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-alpha1-009642\

Host (useful for support):
  Version: 3.0.0-preview1-27004-04
  Commit:  35a0b3f880
leecow commented 5 years ago

cc @diverdan92

Lakritzator commented 5 years ago

@diverdan92 This is the same issue I reported via email, somehow my google-fu didn't find it.. sorry. FYI: I am running with 3.0.100-alpha1-009670

My projects also uses MahApps, which has this dependency on ControlzEx. As this issue has a lot of information, and a much better stacktrace, use this! (I'm already subscribed)

Just in case it's still needed, my project (libraries for Greenshot) to reproduce the error is here (the link brings you to the feature/dotnetcore30 branch!): https://github.com/dapplo/Dapplo.CaliburnMicro/tree/feature/dotnetcore30

It's not so restricted yet, as I first wanted to know if the issue was known before putting time in making a simplified version to reproduce the error.

You probably want to unload all projects with “clickonce” in the name… The startup project should be Application.Demo, you should be able to build and run it. There is a trayicon, withs looks like a #, this has a configuration entry, selecting this causes the error.

diverdan92 commented 5 years ago

@Lakritzator - thanks for the additional details and extra repro project.

@ericstj @jkotas - any ideas who may be a good person to take a look?

jkotas commented 5 years ago

@ericstj Are you able to reproduce this?

Application.Demo from above fails for me pretty early. Here is what I have done:

git clone https://github.com/dapplo/Dapplo.CaliburnMicro/
cd Dapplo.CaliburnMicro\src\Application.Demo
git checkout feature/dotnetcore30
dotnet restore
msbuild
dotnet bin\Debug\netcoreapp3.0\Application.Demo.dll

Result:

Unhandled Exception: System.IO.DirectoryNotFoundException: D:\Application.Demo.Addon\bin\Debug\netcoreapp3.0
   at Dapplo.Addons.Bootstrapper.Resolving.AssemblyResolver.ScanForAssemblies()
   at Dapplo.Addons.Bootstrapper.Resolving.AssemblyResolver..ctor(ApplicationConfig applicationConfig)
   at Dapplo.Addons.Bootstrapper.ApplicationBootstrapper..ctor(ApplicationConfig applicationConfig)
   at Dapplo.CaliburnMicro.Dapp.Dapplication..ctor(ApplicationConfig applicationConfig) in D:\Dapplo.CaliburnMicro\src\Dapplo.CaliburnMicro.Dapp\Dapplication.cs:line 57
Lakritzator commented 5 years ago

@jkotas I mainly develop from within Visual Studio, never checked how got it runs on the commandline. I will see if I can build a clean fix without "hardcoded" paths, right away.

I still advice to look at the ControlZEx example, as it's probably a much better example which doesn't do as much as I did. Like I said before, I use the ControlZEx NuGet Package and this code is most likely that what my Demo crashes.

jkotas commented 5 years ago

ControlZEx example

I was not able to build that one (I did not spend too much time debugging that). When I use the Build.ps1 script in the root, it fails with:

D:\ControlzEx>powershell .\Build.ps1
Preparing to run build script...
Paket version 5.174.2
Performance:
 - Runtime: 1 second
Paket failed with
-> Extracting platforms from path 'netcoreapp3.0' failed
Resolve-Path : Cannot find path 'D:\ControlzEx\packages\cake\Cake' because it does not exist.
Lakritzator commented 5 years ago

@jkotas Actually, I think the problem you had is also due to the fact that you build Application.Demo directly. The application doesn't know about what projects it uses, there are no direct references in the code, so the other projects are not build. The demo needs to demonstrate loading addons at runtime to enhance the UI, this is why... 😄

I made some modifications (git pull), and together with the following steps (bold was modified) it should start:

git clone https://github.com/dapplo/Dapplo.CaliburnMicro/
cd Dapplo.CaliburnMicro\src
git checkout feature/dotnetcore30
dotnet restore
msbuild /p:Configuration=Debug /p:Platform="Any CPU"
dotnet Application.Demo\bin\Debug\netcoreapp3.0\Application.Demo.dll

(tested this)

Lakritzator commented 5 years ago

On a side-note:

  1. As @jkotas has issues building ControlzEx, I also have quite a lot of issues with keeping cake builds stable. I found it a super idea, and it certainly has a lot of potential. I started reducing the functionality to only use it to do all the CI/CD stuff, so I generate documentation, coverage and upload the packages.
  2. I never started the project from the commandline, it actually seems to feel a lot snappier... might just be my imagination.
Lakritzator commented 5 years ago

FYI: Now, if you got things working, you will notice that provoking the error is not really a nice experience from the commandline! The application goes berserk, and opens one window after the other.. this is actually some bad error handling, which tries to show a window -> error -> error handler -> show another window -> error etc... etc..

ericstj commented 5 years ago

@jkotas / @Lakritzator I can repro. I'm seeing lots of noise in this repro but I'll try to get to the bottom of the render thread exception. /cc @vatsan-madhavan @rladuca

Lakritzator commented 5 years ago

@ericstj Thanks for the feedback!

Yeah sorry for all the noise... The project is not specifically made to demonstrate the error, it's pretty much a demo of all the accumulated base library (it has a lot of dependencies) for the "backbone" of the next Greenshot.

I didn't know it might have been in the ControlzEx library code, I only had a stacktrace of internal Microsoft code. This made it hard to reduce the code to the causing code, especially when I only have a time in my "free" evenings to work on this. I wish I would get paid for "playing around" with .NET Code & technologies like you guys 😁 (Daytime job I mainly work with Java)

Anyway, it's now already past midnight for me, so time for bed... With a bit more time, I would probably be able to reduce it to a lot less! If you can't isolate it, I will give it a go tomorrow.

Lakritzator commented 5 years ago

As promised, I created a more isolated repository. See here: https://github.com/Lakritzator/RenderThreadFailure

It has the least noisy code I needed to reproduce the error, but it does just Mahapps.Metro to do so. The issue seems to manifest when a MetroWindow has a GlowBrush, enabling a glow around the window, is shown.

I'm not a MahApps expert, you probably need to look there for what is happening.

Lakritzator commented 5 years ago

In the "alternative" branch of the same project I have used ControlzEx (an alpha) to create the same error by attaching a "GlowWindowBehavior".

It's actually just this:

            var window = new Window();
            var glowWindowBehavior = new GlowWindowBehavior
            {
                GlowBrush = Brushes.Green
            };
            glowWindowBehavior.Attach(window);
            window.Show();
ericstj commented 5 years ago

Awesome, it is a much easier repro and I am seeing the same assert in wpfgfx which indicates its likely the root cause:

MIL FAILURE: Unexpected HRESULT 0x80070715 in caller: batch processing error

This is coming from a failure to FindResource which is looking for resource 0x00000387 (903) in wpfgfx.

00 KERNELBASE!FindResourceW
01 wpfgfx_cor3!CMilEffectDuce::LockResource
02 wpfgfx_cor3!CMilBlurEffectDuce::Initialize
03 wpfgfx_cor3!CMilSlaveHandleTable::CreateEmptyResource
04 wpfgfx_cor3!CComposition::Channel_CreateResource
05 wpfgfx_cor3!CComposition::ProcessCommandBatch
06 wpfgfx_cor3!CComposition::ProcessPartitionCommand
07 wpfgfx_cor3!CCrossThreadComposition::ProcessBatches
08 wpfgfx_cor3!CCrossThreadComposition::OnBeginComposition
09 wpfgfx_cor3!CComposition::ProcessComposition
0a wpfgfx_cor3!CComposition::Compose
0b wpfgfx_cor3!CPartitionThread::RenderPartition
0c wpfgfx_cor3!CPartitionThread::Run
0d wpfgfx_cor3!CPartitionThread::ThreadMain
0e KERNEL32!BaseThreadInitThunk
0f ntdll!RtlUserThreadStart

@vatsan-madhavan this appears to be an issue with the native build of WPFGFX. Seems to be missing some native resources.

See
image

vatsan-madhavan commented 5 years ago

Thanks, taking a look...

Lakritzator commented 5 years ago

Today I will try to workaround the issue, didn't have time for that yet, so I can at least continue with my development for & evaluation of dotnet core 3.0. I still need to mix all my recent changes to the Greenshot repository, where I will add (and thus test) with some of the WinForms functionality.

Still wanted to add a questions to this issue: Is there any information on what wpfgfx_cor3 compared to wpfgfx_v0400 is, and how this is developed? For instance, will this always be developed side by side? How do I see when a new version is supplied, and what changes it has?

Am I correct to assume that wpfgfx it's not open source? Are there any plans on making this more transparent?

ericstj commented 5 years ago

This is a native component in WPF. _v0400 is the one from .net desktop. _cor3 is the one in .net core. It's part of the Microsoft.DesktopUI.App package so you'll see new versions as the SDK updates.

We'll make sure to update this issue with more information about a fix as it is known.

vatsan-madhavan commented 5 years ago

I have a fix that I'm testing right now - should have something out within a day or two.

Lakritzator commented 5 years ago

@ericstj That is pretty much what I understood, was hoping for a bit more 😁

Is the Microsoft.DesktopUI.App open source? Probably not?I think it should be very clearly communicated if not, don't get me wrong: I don't have an issue with it but if dotnet core is open source and it uses closed source components, it might not be received very well if this is not explained.

ericstj commented 5 years ago

I think the latest announcement was @richlander’s comment:

We are investigating that, but haven’t yet made a decision. We’ve been focused on the parts I’ve written about above. We see the value it would have, but don’t have anything to announce yet.

From https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/

Lakritzator commented 5 years ago

@ericstj thanks for the link, I never thought about going back to that "old" blogpost, and read the comments.

Lakritzator commented 5 years ago

@vatsan-madhavan I'm hesitant to ask, but what is the status on this? Is there anything ) can do, or some kind of workaround? It's no problem if you guys need more time, I am asking so I know where to put my priorities.

For the time being I disabled Mahapps Themes, those trigger the glowbehavior, but the UI is missing some stuff and I am not sure if this is due to the theming or a general UI problem...

vatsan-madhavan commented 5 years ago

@Lakritzator Hmm.. I had fixed this a few days ago, and had hoped that the change would have made it to the SDK by now. I'm enquiring...

ericstj commented 5 years ago

Yeah, coresdk is still on a build that's 8 days old: https://github.com/dotnet/core-sdk/blob/b4fe871ab87f6ddc4561efcc3e510a9b529ad5ce/build/DependencyVersions.props#L41 @livarcocc / @nguerrera / @dsplaisted would be the ones to ask if we can have them pick up a new one (and see about automating that codeflow).

Lakritzator commented 5 years ago

@ericstj thanks for the update, not a big problem. But it does give bring up the question on how we are supposed to know what changes are in what build?

nguerrera commented 5 years ago

I'll be inserting the most recent bits later this afternoon.

nguerrera commented 5 years ago

The insertion has been delayed until tomorrow morning in order to pick up another fix and save some effort while they are still manual. I will post a link to a build when it's done.

Lakritzator commented 5 years ago

I updated to 3.0.100-alpha1-009706 and the bug seems to be solved!!!! The example project doesn't crash, and my bigger project also works.

From my point of view, where there is nothing more to do, you can close this issue.

nguerrera commented 5 years ago

Great, glad the update worked, and sorry for the delay and the difficulty of determining when a fix will land in a build.

Lakritzator commented 5 years ago

No problem with the delay, and thanks for fixing it!

m1l commented 5 years ago

This issue has been plaguing all my WPF software since .NET 4.x. Is it possible to apply the solution to WPF?

karelz commented 5 years ago

@m1l I believe this was specific to .NET Core. I recommend to raise the question with details (like repro) on WPF repo.