babalae/better-genshin-impact · error · InvalidOperationException
Failed to create capture item.
Error message
Failed to create capture item.
What it means
CaptureHelper.CreateItemForWindow returns null, so the Windows Graphics Capture API could not create a GraphicsCaptureItem for the given window handle. This guard prevents dereferencing a null _captureItem before reading its Size and building the frame pool.
Source
Thrown at Fischless.GameCapture/Graphics/GraphicsCapture.cs:70
public void Dispose()
{
Stop();
GC.SuppressFinalize(this);
}
public void Start(nint hWnd, Dictionary<string, object>? settings = null)
{
Stop();
try
{
_hWnd = hWnd;
(_region, _captureRect) = GetGameScreenInfo(hWnd);
_captureItem = CaptureHelper.CreateItemForWindow(_hWnd);
if (_captureItem == null)
{
throw new InvalidOperationException("Failed to create capture item.");
}
_surfaceWidth = _captureItem.Size.Width;
_surfaceHeight = _captureItem.Size.Height;
// 创建D3D设备
_d3dDevice = Direct3D11Helper.CreateDevice();
// 创建帧池
try
{
if (!_isHdrEnabled)
{
// 不处理 HDR,直接抛异常走 SDR 分支
throw new Exception();
}
_pixelFormat = DirectXPixelFormat.R16G16B16A16Float;View on GitHub (pinned to a7cb36712d)
Solutions
- Verify hWnd refers to a live top-level window (IsWindow) before calling Start.
- Check the OS version is >= Windows 10 1903 for GraphicsCapture support.
- Re-acquire the game window handle and retry; on persistent failure, fall back to BitBlt or DXGI capture.
Defensive patterns
Strategy: validation
Validate before calling
if (hWnd == IntPtr.Zero || !User32.IsWindow(new HWND(hWnd)))
return; // window not valid, do not call Start Try / catch
try
{
capture.Start(hWnd);
}
catch (InvalidOperationException ex) when (ex.Message == "Failed to create capture item.")
{
// re-acquire window handle or fall back to BitBlt/DXGI
} Prevention
- Re-acquire and validate the game window handle immediately before capture start.
- Gate GraphicsCapture on OS version >= Windows 10 1903.
- Implement a capture-mode fallback chain (GraphicsCapture -> DXGI -> BitBlt).
When it happens
Trigger: hWnd is invalid/zero, the target window has been closed, the handle refers to a child/non-top-level window that cannot be captured, or the OS is older than Windows 10 version 1903 where GraphicsCapture is unavailable.
Common situations: Game window closed between detection and capture; running on Windows 7/8; passing an overlay or helper window handle by mistake; window minimized/destroyed at capture time.
Related errors
- 动作 {snapshot.Description} 执行 {attempts} 次后,等待 {snapshot.Targ
- 鼠标限制区域必须具有有效宽度和高度。
- 临时解除本地鼠标限制失败
- 注册 Raw Input 鼠标设备失败
- 尝试多次后,截图失败!
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4f8cccc1a5182a92.
Report an issue: GitHub.