dotnet/wpf · critical · OutOfMemoryException

D3DERR_OUTOFVIDEOMEMORY

D3DERR_OUTOFVIDEOMEMORY

Error message

SR.MediaContext_OutOfVideoMemory

What it means

When the render partition goes zombie with failure code D3DERR_OUTOFVIDEOMEMORY, MediaContext.NotifyPartitionIsZombie throws OutOfMemoryException(SR.MediaContext_OutOfVideoMemory): the GPU/Direct3D device ran out of video (VRAM) memory, so the renderer cannot continue.

Solutions

  1. Reduce GPU memory usage: remove BitmapCache, shrink cache sizes, avoid stacking many cached visuals or large effects.
  2. Disable or reduce hardware acceleration (RenderOptions.ProcessRenderMode = SoftwareOnly) as a workaround.
  3. Update the GPU driver and test on different hardware; remote into a session with proper GPU support.
  4. Lower resolution/monitor count in the affected scenarios, or release unused images/textures before rendering new ones.

Example fix

// before
img.CacheMode = new BitmapCache { RenderAtScale = 4.0 }; // very large VRAM use
// after
img.CacheMode = new BitmapCache { RenderAtScale = 1.0 }; // or remove CacheMode
// Or force software rendering app-wide:
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
Defensive patterns

Strategy: fallback

Validate before calling

// Detect low-acceleration environments and pre-emptively reduce GPU load:
byte tier = (byte)(RenderCapability.Tier >> 16);
bool useCaching = tier >= 2 && !isRemoteSession;

Try / catch

catch (OutOfMemoryException ex) when (ex.Message.Contains("video")) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; ReduceCacheUsage(); }

Prevention

When it happens

Trigger: NotifySyncChannelMessage/NotifyChannelMessage delivering partition failure with HRESULT D3DERR_OUTOFVIDEOMEMORY — e.g., too many hardware-accelerated layers, large textures/BitmapCache, or multiple full-screen layered windows exhausting VRAM.

Common situations: Apps using many retained BitmapCache / Effect layers, multi-monitor with large desktops on low-VRAM GPUs, remote-desktop sessions where video memory is emulated/limited, driver resets leaking VRAM.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/1548b5fe4fcf95aa. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs:426

        /// The partition this media context is connected to went into
        /// zombie state. This means either an unhandled batch processing,
        /// rendering or presentation error and will require us to reconnect.
        /// </summary>
        private void NotifyPartitionIsZombie(int failureCode)
        {
            //
            // We only get back these kinds of notification:-
            // For all OOM cases, we get E_OUTOFMEMORY.
            // For all OOVM cases, we get D3DERR_OUTOFVIDEOMEMORY and
            // for all other errors we get WGXERR_UCE_RENDERTHREADFAILURE.
            //

            switch (failureCode)
            {
            case HRESULT.E_OUTOFMEMORY:
                throw new System.OutOfMemoryException();
            case HRESULT.D3DERR_OUTOFVIDEOMEMORY:
                throw new System.OutOfMemoryException(SR.MediaContext_OutOfVideoMemory);
            default:
                throw new System.InvalidOperationException(SR.MediaContext_RenderThreadError);
            }
        }

        /// <summary>
        /// The back channel processed a malformed packet and so gives
        /// the notification of invalid packet.
        /// </summary>
        private void HandleInvalidPacketNotification()
        {
            //
            // -
            // For now we ignore the packet and continue processing
            // other packets. In future, we could also close this channel.
            //
        }

View on GitHub (pinned to 81131a70a4)