Repository navigation
Description
This issue has been moved from a ticket on Developer Community.
[severity:Other]
Using the Viewport3D and GeometryModel3D features in .NET 4.8 application seem to always cause an exception when Windows 11 computer resumes from hibernation.
Applying this example XAML into the WPF application template in Visual Studio 2022 produces an application which will throw after computer is hibernated and resumed.
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/how-to-create-a-3-d-scene?view=netframeworkdesktop-4.8#create-a-3d-scene-in-xaml
Sample VS solution:
WPF3DBugTest.zip
Issue repro steps:
- Build the provided application with Visual Studio 2022
- Configure Visual Studio to stop on OutOfMemoryException and run the application with debugger attached
- Hibernate Windows
- Turn computer back on and login
- Try to move or resize the application window
- Visual Studio stops on exception, resuming closes the application.
I have noted that running the application without debugger attached might not cause visible issues, or the repro steps might not be reliable. However, in a more complex application utilizing WPF 3D features an exception always occurs.
The crash occurs as OutOfMemoryException is thrown in WPF render thread.
System.OutOfMemoryException
HResult=0x8007000E
Message=Insufficient memory to continue the execution of the program.
Source=PresentationCore
StackTrace:
at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean enableRenderTarget, Nullable`1 channelSet)
at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr lParam)
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) in MS.Win32\HwndWrapper.cs:line 221
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in MS.Win32\HwndSubclass.cs:line 253
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in System.Windows.Threading\ExceptionWrapper.cs:line 73
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in System.Windows.Threading\ExceptionWrapper.cs:line 24
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in System.Windows.Threading\Dispatcher.cs:line 1021
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in MS.Win32\HwndSubclass.cs:line 207
Windows information:
Edition Windows 11 Pro
Version 24H2
OS build 26100.2314
Experience Windows Feature Experience Pack 1000.26100.32.0
Original Comments
Feedback Bot on 11/20/2024, 07:21 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Activity
Metalfusion commentedon Dec 18, 2024
A workaround seems to be to minimize the application window before hibernating. However, this is not feasible to do programmatically as trying to minimize the app window from the Windows system power management "suspend" event handler doesn't help.
LennyVC commentedon May 19, 2025
Greetings,
Any updates on this? It is causing issues for us frequently.
tormnator commentedon May 20, 2025
We also receive regular error reports from our users with the same exception call stack. We have not attempted to verify that this is related to resuming for hibernation, though. WPF 4.x 3D application.
joshucar commentedon Jul 2, 2025
We are 💯 getting this issue related to hibernation. Our best current workaround is to try to detect the pending hibernation, remove these 3d elements, and reconstruct upon wake. But not super reliable. We are happy to provide any diagnostics/debugging needed to help the WPF team find a resolution!
lindexi commentedon Jul 7, 2025
@joshucar Do you means that any wpf application with the 3D element, will OutofMemory after hibernation? Thank you.
joshucar commentedon Jul 7, 2025
That is what we are seeing, yes. If we have a ModelVisual3D loaded, we will get an OOM when the computer resumes from hibernation or hybrid sleep. We only see this on Windows 11; Windows 10 doesn't seem to cause this issue.
lindexi commentedon Jul 8, 2025
@joshucar How about take the DUMP file to analysis?
joshucar commentedon Jul 9, 2025
@lindexi, what would be a good way to send you what we have - don't think I want to post it here/publicly 🙈
lindexi commentedon Jul 10, 2025
@joshucar You can try your self. Just drag the dump file to Visual Studio to analysis. I cannot guarantee the security of your dump data.
LennyVC commentedon Aug 12, 2025
Hi!
Is there anyway we could escalate this issue?
lindexi commentedon Aug 13, 2025
@LennyVC Do you meet this issues? Could you take the DUMP file to analysis?
LennyVC commentedon Aug 14, 2025
Hi @lindexi !
Is it possible for you to take a .DMP from the sample VS Solution attached to this ticket?
lindexi commentedon Aug 14, 2025
@LennyVC Sorry, I can not repro this issues.
Todilo commentedon Aug 14, 2025
@LennyVC
https://drive.google.com/file/d/1JHuMeRPnApaqst3yVgPAA3cILAFCUDaw/view?usp=sharing
First time creating a dump file so I hope I did it right. I started the sample app. Wait for it to crash and go to error line with the "insufficient memory exception" and then save the .DMP
10 remaining items
Todilo commentedon Sep 4, 2025
I am using windows 11 Home, and sleep.
tormnator commentedon Sep 12, 2025
We added more information to our error reports last week, and we have found one "lead". First, in our case, this is about OutOfMemoryException and the exact same stack trace with UpdateWindowPos as shown in the original post. But, it does not look like this error only happens on wake up. We have 6 error reports since our last release, and 2 of them have come within a few seconds after wake up. But, here's the lead, in all cases, RenderCapability.Tier >> 16 == 0, RenderOptions.ProcessRenderMode == Default, and SystemParameters.IsRemoteSession == False. The computers have a variety of monitor and GPU setups, no pattern there. I'm going to try to gather more information about why the render tier is 0 (e.g. registry information). All computers are Windows 11 (but so are also the vast majority of user computers in general, so this might not mean anything).
One question for now, obviously, is why are we seeing this OutOfMemoryException in render tier 0?
lindexi commentedon Sep 14, 2025
I can't explain this phenomenon, but it is indeed a new "lead". It may means that this doesn't seem to be a universal error, but rather there is a loophole in the implementation of a certain branch.
lindexi commentedon Sep 17, 2025
@Todilo @tormnator Could you help me to continue this issue?
Please run the .NET 10 application demo I built (published together with the debug build of WPF) on your machine and attach Visual Studio to the running process for deeper debugging.
The .NET 10 application demo:
Follow these steps:
Debug>Save Dump Asto create a DUMP file and share that DUMP with me for further analysis.Expected result: when the bug is reproduced, Visual Studio should hit the breakpoint in MilInstrumentationCallHRCheckFunction, and the call stack should provide actionable clues.
wpf/src/Microsoft.DotNet.Wpf/src/WpfGfx/shared/util/UtilLib/Instrumentation.h
Line 130 in ee7cbb8
And you can find my demo code in https://github.com/lindexi/lindexi_gd/tree/06c5d6c55ce91d1dae25c40c281b32e8318f730a/WPFDemo/DarkerbewurNefelearca
Todilo commentedon Sep 17, 2025
tormnator commentedon Sep 18, 2025
@lindexi I have never been able to reproduce the issue on my setup (Lenovo P15s laptop, dock, multiple monitors, Windows 10). I have been further studying the problem today, including adding more data to our internal error reports, and trying various tricks to force the system to fail, or even force render tier 0, without luck. We'll be releasing the next version of our app soon, and will see if the additional data helps (assuming the errors continue).
My hypothesis--for us--is that the OutOfMemoryException in the render thread happens on laptop computers, often times (but not always) related to connecting to/disconnecting from external monitors.
I also found a registry key HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\IgnoreDwmFlushErrors and saw that the path to VS 2022 was added. This made me do a little AI research on it, and it led me to the following links: https://support.microsoft.com/en-us/topic/june-14-2022-kb5013892-cumulative-update-for-net-framework-3-5-and-4-7-2-for-windows-10-version-1809-and-windows-server-version-2019-39351abe-295b-44ea-8099-65632e28f055 and https://www.perplexity.ai/search/in-the-windows-registry-under-HuK57WIuRZiOSXFwfI60Uw?0=d
So, maybe this is a known issue after all, and maybe we should also add our app(s) to that registry key? One observation which might support this is that our error logs show that users who get the OOM exception are able to continue the application afterwards. WPF documents seem to indicate that the render thread is "zombied" after the error and will not work anymore, but that does not seem to be the case here. But who knows...
lindexi commentedon Sep 18, 2025
@Todilo The main difference point is the application I provided is the debug version.
lindexi commentedon Sep 18, 2025
@tormnator Thank you for your experience. And the OOM you receive is from the wpfgfx's HR result value, which not means that the wpf render thread completely break. But in most cases, it will break the render thread.
Todilo commentedon Sep 18, 2025
@lindexi
I understand that it is a debug version. I do seem to be getting different behaviours though. Or more precisely if I run from visual studio I get the crash, but running from any published version I do not(tried running as .net 9 as well as .net 10 targeting multiple differnt OS). All published versions work, studio does not.
lindexi commentedon Sep 18, 2025
@Todilo Running from VisualStudio will be attached the XAML hot reload, and which may cause some behavior changed.
tormnator commentedon Oct 7, 2025
I have an update on the OutOfMemoryException. Out application's telemetry is now more detailed and I have included a few incidents in a report at the bottom of this message. The text in the report has been cleaned up by me. What we see is that the computers are laptops; at some point they enter suspended state, and at that point the application's Graphics Rendering Tier is changed to 0. When the computer later resumes from suspended state, the Graphics Rendering Tier does not return to 2 as expected. And then, at some point later, sometimes almost immediately, but other times quite a bit later, the OutOfMemoryException is thrown.
My hypothesis is that the OutOfMemoryException is legitimate, and that it happens because the application environment runs out of some resource due to running in Graphics Rendering Tier 0 with software rendering. If this is correct, then the primary task now is to see if there's a way to get the application to recover from Graphics Rendering Tier 0, if we somehow can coerce the application to reset/restore Graphics Rendering Tier 2. Secondarily, it would be good to know why it enters Graphics Rendering Tier 0 when entering suspended state, maybe this is correct, maybe not. And finally, it would be good to know why it doesn't restore Graphics Rendering Tier 2 when resuming from suspended state. Here's the report:
Malin, 1st incident:
10/01/2025 06:28:57 Application started
10/01/2025 06:28:58 Console display state on
10/01/2025 06:28:58 Lid opened
10/01/2025 06:28:58 Power source AC
10/01/2025 07:39:01 Console display state off
10/01/2025 07:15:22 Console display state on
(Multiple events, including suspending and resuming...)
10/01/2025 10:29:12 Lid closed
10/01/2025 10:35:20 Console display state off
10/01/2025 15:39:55 Power broadcast suspend
10/01/2025 15:39:55 Computer entered suspended state
10/01/2025 15:39:56 Graphics Rendering Tier set to 0
10/03/2025 04:08:07 Lid opened
10/03/2025 04:08:08 Power broadcast resume from suspend
10/03/2025 04:08:09 Computer resumed from suspended state
10/03/2025 04:08:09 Power broadcast resume automatic
10/03/2025 04:08:09 Console display state on
10/03/2025 04:08:15 OutOfMemoryException (in UpdateWindowsSettings -> SyncFlush)
Only the laptop's built-in display is present at the time of the exception
Malin, 2nd incident:
10/04/2025 14:04:52 Application started
10/04/2025 14:04:54 Lid opened
10/04/2025 14:04:54 Power source AC
10/04/2025 14:04:54 Console display state on
10/04/2025 15:37:52 Console display state off
10/04/2025 15:46:53 Console display state on
10/04/2025 15:47:23 Console display state off
10/04/2025 15:53:11 Lid closed
10/04/2025 15:57:44 Power source DC
10/04/2025 20:57:45 Computer entered suspended state
10/04/2025 20:57:45 Power broadcast suspend
10/04/2025 20:57:45 Graphics Rendering Tier set to 0
10/05/2025 07:39:19 Lid opened
10/05/2025 07:39:20 Power broadcast resume automatic
10/05/2025 07:39:20 Power broadcast resume from suspend
10/05/2025 07:39:20 Computer resumed from suspended state
10/05/2025 07:39:20 Console display state on
10/05/2025 07:39:25 OutOfMemoryException (in UpdateWindowsSettings -> SyncFlush)
Only the laptop's built-in display is present at the time of the exception
Terje:
10/05/2025 14:42:10 Application started
10/05/2025 14:42:12 Power source AC
10/05/2025 14:42:12 Console display state on
10/05/2025 14:42:12 Lid opened
10/05/2025 15:02:50 Console display state off
10/05/2025 15:08:17 Power broadcast suspend
10/05/2025 15:08:18 Computer entered suspended state
10/05/2025 15:08:18 Graphics Rendering Tier set to 0
10/05/2025 15:38:27 Power broadcast resume from suspend
10/05/2025 15:38:27 Computer resumed from suspended state
10/05/2025 15:38:27 Power broadcast resume automatic
10/05/2025 15:38:27 Console display state on
10/05/2025 15:39:38 OutOfMemoryException (in UpdateWindowsSettings -> SyncFlush)
Only the laptop's built-in display is present at the time of the exception
lindexi commentedon Oct 9, 2025
@tormnator Thank you for your detailed experimental records.
But I can not find any usable information from the DUMP file, which means that it do not look like the app runs out of the resources.
abenedik commentedon Dec 10, 2025
I am also very interested in this problem because I am the author of Ab3d.PowerToys library that helps use WPF 3D graphics.
The link that you posted to get the debug wpfgfx_cor3.dll and .pdb file does not work anymore. But I was able to compile the WPF source code - actually, there were many errors, but I managed to get at least the debug version of wpfgfx_cor3.dll for x86.
After that, I put a breakpoint in the MilInstrumentationCallHRCheckFunction, as you have instructed.
After resuming from sleep, I got an error with hr codes with 0x8876086a (D3DERR_NOTAVAILABLE) error after calling
pID3D->CheckDeviceType. Then I got a few times 0x8876086a after callingCD3DDeviceLevel1::PresentWithD3D. But after that, the code ran fine and the 3D graphics was correctly shown. There were no E_OUTOFMEMORY that usually happened after resuming from sleep.After some experimenting, I found that if I stopped at the first breakpoint, this seems to give enough time to the system (or whatever component) to initialize after sleep. So I changed the breakpoint to add a condition to only break when E_OUTOFMEMORY happened, and then I was finally able to see the problem: after returning from sleep, the WPF code may be executed too quickly - before any hardware render target is available. In this case the code tries to create a software rendering render target and this creation fails. This stops rendering and reports the E_OUTOFMEMORY to the UI thread, crashing the app.
Here are more details:
When the WPF app starts for the first time, the code in
CMetaRenderTarget::Begin3Dcalls theFindFirstEnabledRT(&idxFirstEnabledRT):On my computer when the app is started the m_cRT is 1 and the m_rgMetaData[0] is:
Notice the pHwDisplayRT is set, but pSwHWNDRT is null.
But after resuming from sleep the same code has the following single element in m_rgMetaData:
In this case the pHwDisplayRT is null and instead the pSwHWNDRT is set.
I was not able to find the code that fills the m_rgMetaData. But I assume that if the FindFirstEnabledRT is executed too soon after resuming from sleep, the system was not yet able to initialize the graphics hardware and because of this tries to use software rendering.
After that, the code continues on a different path then after the app was started.
This path starts with the following code (below are the parameters that are passed to the Create function):
Now the code tries to create the software render target. But this fails in
CD3DModuleLoaderInternal::RegisterSoftwareDevicewhen callingpID3D->RegisterSoftwareDevice(m_pfnSwRastD3D9GetSWInfo).The
m_pfnSwRastD3D9GetSWInfois a pointer to a function atrgb9rast.dll!0x60e826f0(I have no symbols for that file).This call returns E_OUTOFMEMORY that is than propagated to the start and then passed to the main thread.
Here is the full call stack (I added a new line to the
CMetaRenderTarget::Begin3Dthat starts the path of creating the software RT:I hope that this will help you find the solution to the problem. As you have found out, this does not happen on all computers. Here this works fine on Win 11 laptop, but crashes as described above on a brand new high end desktop PC with NVIDIA GPU.
I am also not sure why this seems to only break when WPF is showing some 3D graphics.
If you need any additional information, please tell me and I will be glad to help.
lindexi commentedon Dec 11, 2025
Thank you @abenedik And I updated the download link in #10192 (comment)
Your information is very important. As your information says,
pID3D->CheckDeviceTypewill return 0x8876086a(D3DERR_NOTAVAILABLE). And I think this points to the core issue.As the https://learn.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3d9-checkdevicetype document says:
But I don't know what the next solution will be now. How about wait whatever?
abenedik commentedon Nov 30, 2026
After some additional time debugging this issue, I prepared a PR that fixes this issue.
Please check the description in the PR for more info.
I hope that this will be merged and will come in a update.
If you would like that I do some additional tests or change something, please let me know.