dotnet / dotnet/wpf

WPF 3D model example throws OutOfMemoryException from render thread after resuming from hibernation

Open
#10,192 38 comments 5 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/WPF-3D-model-example-throws-OutOfMemoryE/10793983)._

---
[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](https://aka.ms/dc/file?name=B6ae0c4a614104028a101029fc5486400638676163101131965_WPF3DBugTest.zip&tid=6ae0c4a614104028a101029fc5486400638676163101131965)

**Issue repro steps:**
1. Build the provided application with Visual Studio 2022
2. Configure Visual Studio to stop on OutOfMemoryException and run the application with debugger attached
2. Hibernate Windows
3. Turn computer back on and login
4. Try to move or resize the application window
5. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.