You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You need 2 monitors with different screen resolution.
Start app on main monitor and maximize it
Power off this monitor or change display settings to display only on second monitor
Windows will move the application to the second monitor and it will crash with UCEERR_RENDERTHREADFAILURE
Source of the problem
It looks like IDirect3D9.GetAdapterMonitor will return 0 because monitor is powered off (or unavailable) and function pDisplaySet->GetDisplayIndexFromMonitor(hMon, uDisplayIndex) in CInteropDeviceBitmap::GetDisplayFromUserDevice will return E_INVALIDARG and this eventually will lead to crash.
So to me it looks like issue is in D3DImage that connected to adapter 0 while adapter 0 is disconnected from monitor.
Fix*
To fix it I declared private EventHandler renderingEventHandler; in MainWindow.xaml.cs then set rendering like this:
renderingEventHandler = new EventHandler(CompositionTarget_Rendering);
CompositionTarget.Rendering += renderingEventHandler;
and lastly I added 3rd parameter true to every call to SetBackBuffer and removed d3dimg.IsFrontBufferAvailable check in CompositionTarget_Rendering.
Does anybody know if this approach to detect monitor changes (using Microsoft.Win32.SystemEvents.DisplaySettingsChanging) is correct?
Just in case if somebody thing it is rare thing, we have 37933 crash reports from users for this issue. I'm not sure how many related to this particular reason but at least some are.
Here is one of reports from our customers: "I also get this issue on my Lenovo laptop when connecting/disconnecting external monitors." Some customers state that it happened when computer is going to sleep or perhaps when monitors going to sleep but I couldn't able to reproduce it.
The text was updated successfully, but these errors were encountered:
Use a laptop with connected HDMI external display, set display settings to “Extend”. DPI doesn’t matter.
In the OS control panel, set “when I close the lid” = “Do nothing”.
Run a .NET 4.8 WPF app which uses D3DImage on the internal monitor.
Close the lid.
It looks like IDirect3D9.GetAdapterMonitor will return 0 because monitor is powered off (or unavailable)
I can confirm the source is correct.
Your workaround didn’t work for me because I don't want to render the 3D content at refresh rate of the monitor, but I was able to workaround using MinHook to replace IDirect3D9.GetAdapterMonitor API method for the current process, changing nullptr return value to the handle of the primary monitor.
Implementing the fix on the WPF side would be way simpler. Literally 2 lines of code in CInteropDeviceBitmap::GetDisplayFromUserDevice method, after the pID3DUserObject->GetAdapterMonitor line:
I know that are many reasons for this error but I found that for my case it was related to using D3DImage.
Here is link to the project that demonstrates problem : https://github.com/vladimir-cheverdyuk-altium/dx9host
Basically it is Microsoft code copied from here:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-creating-direct3d9-content-for-hosting-in-wpf?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-hosting-direct3d9-content-in-wpf?view=netframeworkdesktop-4.8
It has project for .NET Framework and .NET6.
Steps:
Source of the problem
It looks like IDirect3D9.GetAdapterMonitor will return 0 because monitor is powered off (or unavailable) and function
pDisplaySet->GetDisplayIndexFromMonitor(hMon, uDisplayIndex)
inCInteropDeviceBitmap::GetDisplayFromUserDevice
will return E_INVALIDARG and this eventually will lead to crash.So to me it looks like issue is in D3DImage that connected to adapter 0 while adapter 0 is disconnected from monitor.
Fix*
To fix it I declared
private EventHandler renderingEventHandler;
inMainWindow.xaml.cs
then set rendering like this:and add these 2 lines to the end of constructor:
and lastly I added implementation:
and lastly I added 3rd parameter
true
to every call toSetBackBuffer
and removedd3dimg.IsFrontBufferAvailable
check inCompositionTarget_Rendering
.Does anybody know if this approach to detect monitor changes (using Microsoft.Win32.SystemEvents.DisplaySettingsChanging) is correct?
Just in case if somebody thing it is rare thing, we have 37933 crash reports from users for this issue. I'm not sure how many related to this particular reason but at least some are.
Here is one of reports from our customers: "I also get this issue on my Lenovo laptop when connecting/disconnecting external monitors." Some customers state that it happened when computer is going to sleep or perhaps when monitors going to sleep but I couldn't able to reproduce it.
The text was updated successfully, but these errors were encountered: