{"record":{"id":"4f8cccc1a5182a92","repo":"babalae/better-genshin-impact","slug":"failed-to-create-capture-item","errorCode":null,"errorMessage":"Failed to create capture item.","messagePattern":"Failed to create capture item\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Fischless.GameCapture/Graphics/GraphicsCapture.cs","lineNumber":70,"sourceCode":"    public void Dispose()\n    {\n        Stop();\n        GC.SuppressFinalize(this);\n    }\n\n    public void Start(nint hWnd, Dictionary<string, object>? settings = null)\n    {\n        Stop();\n        try\n        {\n            _hWnd = hWnd;\n            (_region, _captureRect) = GetGameScreenInfo(hWnd);\n\n            _captureItem = CaptureHelper.CreateItemForWindow(_hWnd);\n\n            if (_captureItem == null)\n            {\n                throw new InvalidOperationException(\"Failed to create capture item.\");\n            }\n\n            _surfaceWidth = _captureItem.Size.Width;\n            _surfaceHeight = _captureItem.Size.Height;\n\n            // 创建D3D设备\n            _d3dDevice = Direct3D11Helper.CreateDevice();\n\n            // 创建帧池\n            try\n            {\n                if (!_isHdrEnabled)\n                {\n                    // 不处理 HDR，直接抛异常走 SDR 分支\n                    throw new Exception();\n                }\n\n                _pixelFormat = DirectXPixelFormat.R16G16B16A16Float;","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/Fischless.GameCapture/Graphics/GraphicsCapture.cs#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (hWnd == IntPtr.Zero || !User32.IsWindow(new HWND(hWnd)))\n    return; // window not valid, do not call Start","typeGuard":null,"tryCatchPattern":"try\n{\n    capture.Start(hWnd);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Failed to create capture item.\")\n{\n    // re-acquire window handle or fall back to BitBlt/DXGI\n}","preventionTips":["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)."],"tags":["capture","graphics-capture","win32"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}